I have several virtual machines running Ubuntu at my home
that have static IPs for various reasons.
Prior to Ubuntu 12.04 I would simply edit /etc/network/interfaces to
something like this.
auto lo
iface lo inet loopback
#
#
auto eth0
iface eth0 inet static
address
192.168.0.100
netmask
255.255.255.0
broadcast
192.168.1.255
gateway
192.168.0.1
|
But in Ubuntu 12.04 this does not work, well it works but
you can no longer access anything. apt-get
no longer works, ping no longer works, wget no longer works.
This is not because of
change in how Ubuntu handles this file but an update in how Ubuntu
handles /etc/resolv.conf file. There is
a discussion and some links on the changes, and how it effects a static IP
address in Ubuntu at http://askubuntu.com/questions/180925/how-to-setup-static-ip-in-ubuntu-server-12-04
[1]
But, long story short this file is no longer a static file
it is a script that gets updated every reboot.
To fix this situation this is what I did.
First update the /etc/network/interfaces file to get the DNS
servers you are using
> sudo vi /etc/network/interfaces
|
And update it to
auto eth0
iface eth0 inet
dhcp
|
Then reboot the server
> sudo reboot now
|
Now see what is in the /etc/resolv.conf folder
> sudo cat /etc/resolv.conf
|
Here it found my
local DNS servers. I run a local DNS
server at 192.168.0.153 and a DNS server from my local ISP provider
Copy your DNS server
IP addresses down.
Now edit /etc/network/interfaces
> sudo vi /etc/network/interfaces
|
And update it to
auto lo
iface lo inet
loopback
#
#
auto eth0
iface eth0 inet
static
address 192.168.0.111
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.0.1
dns-nameservers 192.168.0.153 207.14.XXX.XXX
|
This adds the DNS nameservers to the definition
Then reboot the server
> sudo reboot now
|
Of course you could run
> sudo /etc/init.d/network restart
|
But you should reboot as the /etc/resolv.conf file is
overwritten every reboot and you want to make sure this setup works for you
through a reboot.
References
[1] How to setup
static IP in Ubuntu Server 12.04?
Visited 01/2012
No comments:
Post a Comment