Change Ubuntu Server from DHCP to a Static IP Address
2012-02-24 17:17
441 查看
Change Ubuntu Server from DHCP to a Static IP Address - How-To Geek
Changing this setting without a GUI will require some text editing, but that’s classic linux, right?
Let’s open up the /etc/network/interfaces file. I’m going to use vi, but you can choose a different editor
sudo vi /etc/network/interfaces
For the primary interface, which is usually eth0, you will see these lines:
You need to also remove the dhcp client for this to stick (thanks to Peter for noticing). You might need to remove dhcp-client3 instead.
Really pretty simple.
Updated Thanks to Nickname007 in the comments for noting that I forgot the DNS entries in the guide.
Change Ubuntu Server from DHCP to a Static IP Address
If the Ubuntu Server installer has set your server to use DHCP, you will want to change it to a static IP address so that people can actually use it.Changing this setting without a GUI will require some text editing, but that’s classic linux, right?
Let’s open up the /etc/network/interfaces file. I’m going to use vi, but you can choose a different editor
sudo vi /etc/network/interfaces
auto eth0
iface eth0 inet dhcp
As you can see, it’s using DHCP right now. We are going to change dhcp to static, and then there are a number of options that should be added below it. Obviously you’d customize this to your network.iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
Now we’ll need to add in the DNS settings by editing the resolv.conf file:iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
sudo vi /etc/resolv.conf
On the line ‘name server xxx.xxx.xxx.xxx’ replace the x with the IP of your name server. (You can do ifconfig /all to find out what they are)You need to also remove the dhcp client for this to stick (thanks to Peter for noticing). You might need to remove dhcp-client3 instead.
sudo apt-get remove dhcp-client
Now we’ll just need to restart the networking components:sudo /etc/init.d/networking restart
Ping www.google.com. If you get a response, name resolution is working(unless of course if google is in your hosts file).Really pretty simple.
Updated Thanks to Nickname007 in the comments for noting that I forgot the DNS entries in the guide.
相关文章推荐
- change the DHCP address to static address at home
- How to change IP address of your ESX Server
- How to Find Your IP Address in Ubuntu Linux
- 第一次使用Genymotion遇到的问题:for an unknown reson,VirtualBox DHCP has not assigned an IP address to virtual
- How do I change the FROM address to a friendly name?
- ubuntu change ip address
- Linux Force DHCP client (dhclient) to renew ip address
- ubuntu: change the path from openjdk to oracle jdk
- Setting up a static IP address in Ubuntu
- Ubuntu 14.04 server配置使用无线连接DHCP获取IP
- Ubuntu 11.04 Change From Unity To Classic Gnome
- Beginning Ubuntu LTS Server Administration: From Novice to Professional, Second Edition
- Ubuntu 8.10 static IP address bug solution
- Linux Force DHCP Client (dhclient) to Renew IP Address
- Simplest way to serve static data from outside the application server in a Java web application
- How to change the network IP addresses of SQL Server failover cluster instances-[From MS]
- How To Set Up A USB-Over-IP Server And Client With Ubuntu 10.04
- 第一次使用Genymotion遇到的问题:for an unknown reson,VirtualBox DHCP has not assigned an IP address to virtual
- How To: Make VirtualBox Use Your Router’s DHCP to get an IP Address in Linux