Multiple IP adresses for network device
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).
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!
Same here.
Seems to be broken on Ubuntu 11.10
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
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.
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
thanks!