Setup multiple IP addresses on Ubuntu - Adventures in Switching to Linux

Friday, May 30, 2008

Setup multiple IP addresses on Ubuntu

I'm working on migrating a server again today and we decided that we want to put some of the services on 1 IP and the others on another so if we ever need to move one set of services over the IP can follow. This is the machine that is running Ubuntu 8.04 Server.

It turns out this is a pretty simple thing to do. First, edit your interfaces file:

sudo nano -w /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

Then add in a few new lines below the eth0 section to create a new virtual interface:
auto eth0:0
iface eth0:0 inet static
address 10.10.10.200
netmask 255.255.255.0
Then restart your networking:

$ sudo /etc/init.d/networking restart

And there you have it, your new virtual interface with your new IP.

$ ifconfig
eth0 Link encap:Ethernet HWaddr 00:1d:09:15:74:af
inet addr:10.10.10.122 Bcast:10.10.10.255 Mask:255.255.255.0
inet6 addr: fe80::21d:9ff:fe15:74af/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:52 errors:0 dropped:0 overruns:0 frame:0
TX packets:42 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9780 (9.5 KB) TX bytes:5388 (5.2 KB)
Interrupt:17

eth0:0 Link encap:Ethernet HWaddr 00:1d:09:15:74:af
inet addr:10.10.10.200 Bcast:10.10.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:17

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:16436 Metric:1
RX packets:38081 errors:0 dropped:0 overruns:0 frame:0
TX packets:38081 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1614360 (1.5 MB) TX bytes:1614360 (1.5 MB)

Thanks go to NukeSilo.com for getting me started and the Debian guide on Network configuration for all the details.

8 comments:

Cyle said...

Thanks for the explanation as it is simple and easy to understand.

Teknologi Hari Ini said...

Yes , i found that this post is the easiest way :D.
Thx bradahh!!

Forrest said...

If after doing this you get a "Network unreachable" message, add a "gateway" and restart.

Unknown said...

you said set up multiple IP addresses - but I only see one IP address in your example

Anonymous said...

Alex, look closer. The primary interface is eth0 on 10.10.10.122. The added virtual interface is eth0:0 on 10.10.10.200.

By the way, I've bookmarked and come back to this post several times. Great job!

Anonymous said...

How this can work? Both interface have same MAC.

MrVertigo27 said...

Still works beautifully!!!!!

tc7 said...

Great job - worked first time (remotely). Very happy.