Linux and Windows IT Support  

dedicated-technology-experts

Windows, Apple and Linux IT support and services.

For Software and Web Development.

Multiple IP adresses for network device

PrintE-mail

Q. I am using Ubuntu Linux and I would like to know how to create alias for eth0 so that I can have multiple IP address?

A. To create alias for eth0 use ifconfig command. It is use to configure a network interface and aliases.

Assuming that your eth0 IP is 192.168.1.10 and you would like to create an alias eth0:0 with IP 192.168.1.11. Type the following command:

sudo ifconfig eth0:0 192.168.1.11 up

OR

sudo /sbin/ifconfig eth0:0 192.168.1.11 up

Verify that alias is up and running using following two command(s):

/sbin/ifconfig
ping 192.168.1.11
ping your-getway-ip

Permanent configuration

Your ethernet configuration is located in a file called /etc/network/interfaces. If you reboot system you will lost your alias. To make it permanent you need to add it network configuration file:

sudo vi /etc/network/interfaces

OR

sudo vi /etc/network/interfaces

Append the following configuration:

auto eth0:0
iface eth0:0 inet static
name Ethernet alias LAN card
address 192.168.1.11
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0

Save the file and restart system or restart the network:

sudo /etc/init.d/networking restart

Please note that you can also use graphical tools located at System > Administration > Networking menu. Or use the following GUI tool to setup aliases, hostname, dns settings etc:

sudo network-admin

If you want more network aliases, use eth0:1, eth0:2, eth0:N (max upto 254).

Comments (9)
Two public IPs to help out firewall?
9 Thursday, 07 March 2013 07:00
George
Hi All,
Just a question - let's say I'd like to use two public IPs. One for the host machine and the other for VMs in the DMZ. Therefore, all I need to do is create alias eth0.0, set additional public IP to it and postroute all the traffic to e.g. 192.168.0.0/24 network? Will it work? Is it better solution than creating vmbr0?
My idea is to hide the first IP that I'm using for the host machine and "publicly" use only the second one with port forwarding on.
Thanks a bundle!
Works
8 Tuesday, 07 February 2012 06:31
Tim
Works on Ubuntu 11.10 but is easier with gedit instead of vi :D
permanent setting on Ubuntu 11.10
7 Monday, 23 January 2012 04:13
Marcel
"Now I want to make it permanent but I can't figure out what to add to my /etc/network/interfaces file. "
Same here.
Seems to be broken on Ubuntu 11.10
Details
6 Wednesday, 11 January 2012 13:27
Rurinho
Hi.

I'm new to linux.
I'm trying to access 2 networks from the same pc with 1 NIC.

Main network:
IP: 192.168.15.30
Mask: 255.255.255.0
Gateway: 192.0168.15.254

Secondary network:
IP: 192.168.1.30
Mask: 255.255.255.0
Gateway: 192.168.1.254

I tried your example:

sudo ifconfig eth0:0 192.168.1.30 up

and it worked fine.

Now I want to make it permanent but I can't figure out what to add to my /etc/network/interfaces file.

auto eth0:0
iface eth0:0 inet static
name Ethernet alias LAN card
address 192.168.1.30
netmask 255.255.255.0
broadcast 192.168.1.254
network 192.168.1.254

Is this correct?
It is not working for me.

Thanks in advance.

Regards,
Rurinho
re: how to define route
5 Monday, 28 November 2011 11:24
Ant
@Umar: I'm not sure how you would do that with DHCP, you'll need a way to get an IP address in your config. You can try using variables: EXTIP, EXTMASK, etc. I assume that eth0 is your EXTERNAL card and eth1 is your INTERNAL card:

In /etc/iproute2/rt_tables, add those two at the bottom:

#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
1 first
2 second

then, in /etc/rc.local add the following (before exit 0):

EXTIP="`/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"
EXTMASK="`/sbin/ifconfig eth0 | grep 'mask' | awk '{print $4}' | sed -e 's/.*://'`"
EXTNET="`/sbin/route -n | grep 'eth0' | awk '{print $1}' | sed -e 's/\0\.\0\.0\.0//'`"
EXTGW="`/sbin/route -n | grep 'eth0' | awk '{print $2}' | sed -e 's/\0\.\0\.0\.0//'`"

ip route add $EXTNET/$EXTMASK dev eth0 src $EXTIP table first
ip route add default via $EXTGW table first

ip route add 10.64.99.0/24 dev eth1 src 10.64.99.11 table second
ip route add default via 10.64.99.1 table second

ip rule add from $EXTIP table first
ip rule add from 10.64.99.11 table second

It should work, in theory. (I haven't tested it with variables, I use static IPs in all my setups). If that doesn't work, you'll have to manually replace the variables with IPs. This will give you 2 routes, with access to both external and internal networks.
how to define route
4 Monday, 28 November 2011 10:40
Umar
no both are different... i have two Ethernet cards one has IP address (local) and the other one is without IP(internet)
but my it goes directly to internet... in windows i defined routes so i was able to use both networks at one time.
hope you understand my problem
details for my network is given below:
IP address:10.64.99.11
Subnet MAsk: 255.255.255.0
Gateway : 10.64.99.1
DNS Server : 10.202.103.5

hope you understand my problem
re: how to define route
3 Monday, 28 November 2011 10:32
Ant
@Umar: you'll have to do source routing in order to achieve this. What exactly are you trying to do? Are you accessing the same subnet or 2 different ones?
how to define route
2 Monday, 28 November 2011 10:28
Umar
i have two Ethernet card in my pc. i am using Ubuntu 11.10 and want to define network route. can someone please help me in this.... thanks
Works
1 Monday, 14 November 2011 19:20
Carl
Tested on Ubuntu 10.04.
thanks!

Add your comment

Your name:
Subject:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:
yvComment v.1.24.0
   
Copyright © 1999 - 2024 Virtual Helpme | Managed IT Solutions Specialized for Your Business | Original Template: Allrounder