Sunday, December 29, 2013

Setting and Unsetting a Static IP on Ubuntu or Linux Mint with Virtualbox (Use Router DHCP Instead)

Hi, Had to setup (or more accurately unsetup) a static IP on Ubuntu / Linux Mint recently. It's fairly simple to do (and covered in other places on the web).

What's not covered is in Saucy Salamander (or perhaps earlier) is how to remove a static IP once set. I had to do this because I was moving a virtual machine from one computer to another. The old computer had an internal network and was getting its IP from a firewall virtual machine, 10.0.0.1 . I wanted to convert it to use the router's DHCP to simplify things.

So, modify the /etc/network/interfaces file but be prepared to do the following if you are changing network cards / static IPs:

1. Backup then delete the file /etc/udev/rules.d/70-persistent-net.rules . If the MAC address of the network card changed, then you want to delete/edit/remove this.

2. Remove the nameservers from /etc/resolvconf/resolv.conf.d/ in the base head tail files. This is different than the usual /etc/resolvconf/resolvconf.d which is no longer in use in Saucy (and perhaps earlier).

3. Use the router screen to assign the IP to eth0 instead of configuring it in /etc/network/interfaces file. This saves a lot of headaches in the future. Get the MAC address of the output and assign all devices connecting with that MAC address in the router/firewall a static IP.

eth0      Link encap:Ethernet  HWaddr 08:00:27:95:f5:4a
          inet addr:192.168.1.13  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe95:f54a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:169271 errors:0 dropped:0 overruns:0 frame:0
          TX packets:137399 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:167822172 (167.8 MB)  TX bytes:15632156 (15.6 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:8803 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8803 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:691215 (691.2 KB)  TX bytes:691215 (691.2 KB)


4. If using Virtualbox, choose bridged instead of NAT if you want your router instead of Virtualbox to assign the IP. Of course I know what bridged and NAT is, but I had a brain fart and didn't realize the 10.0.2.15 address was a default address assigned by Virtualbox because I chose NAT instead of bridged. So I wasted two hours inside Ubuntu when I should have fixed Virtualbox instead.

5. Forward necessary ports from your router to your new virtual machine / install, and restart a few times and run ifconfig to see if you are getting the proper IP address.

6. You may have to use ifconfig eth0 up if you don't see the network interface up. Similarly, if ping google.ca doesn't work you may need to resolvconf -d eth0 to remove the incorrect DNS servers. All the DNS servers should be set in your router (physical router). If you want to use Google DNS, better to set it up in your router than on the operating system. resolvconf causes major headaches, because editing the text file manually doesn't work.

Hope the above was helpful. Next time I will write about how to setup a small virtual network with Virtualbox so you can create your own lab of virtual machines.

No comments:

Post a Comment