Q. I would like to create alias for my network card (NIC). How do I setup 2 IP address on One NIC? How do I add alias under Centos / Fedora / Debian / Ubuntu Linux?
A. Linux allows you to add additional network address using alias feature. Please note that all additional network IP address must be in same subnet. For example if your eth0 using 192.168.1.5 IP address then alias must be setup using 192.168.1.0/24 subnet.
ifconfig command line
You can use ifconfig command to configure a network interface and alias. For example:
- eth0 NIC IP 192.168.1.5
- eth0:0 first NIC alias: 192.168.1.6
To setup eth0:0 alias type the following command as the root user:
# ifconfig eth0:0 192.168.1.6 up
Verify alias is up and running using following command:
# ifconfig -a
# ping 192.168.1.6
However, if you reboot the system you will lost all your alias. To make it permanent you need to add it network configuration file.
Debian / Ubuntu Linux Instructions
You can configure the additional IP addresses automatically at boot with another iface statement in /etc/network/interfaces:
# vi /etc/network/interfaces
Append text as follows:
auto eth0:1 iface eth0:1 inet static name Ethernet alias LAN card address 192.168.1.7 netmask 255.255.255.0 broadcast 192.168.1.255 network 192.168.1.0
Save and close the file. Restart the network:
# /etc/init.d/networking restart
Red Hat / RHEL / CentOS / Fedora Linux Instructions
Copy etc/sysconfig/network-scripts/ifcfg-eth0 file as /etc/sysconfig/network-scripts/ifcfg-eth0:0
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0
Open file /etc/sysconfig/network-scripts/ifcfg-eth0:0 using vi text editor:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
Find entry that read as follows:
DEVICE=eth0
Replace with:
DEVICE=eth0:0
Find entry that read as follows:
IPADDR=xxx.xxx.xxx.xxx
Replace it with your actual IP address:
IPADDR=192.168.1.7
At the end your file should like as follows:
DEVICE=eth0:0 IPADDR=192.168.1.7 NETMASK=255.255.255.0 NETWORK=192.168.1.0 ONBOOT=yes NAME=eth0:0
Open file /etc/sysconfig/network-scripts/ifcfg-eth0 and make sure file does not have a GATEWAY= entry:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Find the entry that read as follows:
GATEWAY=your-ip
Remove or comment it out by prefixing # (hash) :
# GATEWAY=192.168.1.254
Save the file. Add the GATEWAY= to your /etc/sysconfig/network:
# vi /etc/sysconfig/network
Append or modify GATEWAY entry:
GATEWAY=192.168.1.254
Save the file. Reboot the system or run the following command:
# ifup eth0:0
OR
# service network restart
Red Hat / CentOS / Fedora Multiple IP address range
You can assign multiple ip address range as follows to eth0:
vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0
Append following code from 202.54.112.120 to 202.54.112.140:
IPADDR_START=202.54.112.120 IPADDR_END=202.54.112.140 CLONENUM_START=0 NETMASK=255.255.255.0
Save and close the file.
See also:
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 16 comments… read them below or add one }
Hello there
I am using Linux enterprise 4 on my Toshipa Laptop but it didn’t recognizing my NIC so I had to ask for the NIC installation file so I get and this is the name of the file install_8_37[1].tar but I dont know what to do after that ,so i need any help to do this but just please make simple and much details as much as you can because I am not quite expert.
This blog explains how to create an aliased interface using a C program.
Link
Might be useful for some of you I guess.
Hello, I am very new to Linux. Currently using Ubuntu and was wondering what the following line means.
“name Ethernet alias LAN card”
Any help on this would be great thanks!
thanks !..will try to ad failover ip’s on my ovh box :)
Hi sir
If I have several additional IPs, will creating eth0:1, eth0:2 and so on.
work’s ?
thanks :D
According to the documentation in /usr/share/doc/initscripts-*/sysconfig.txt, the file defining the eth0:0 device on RedHat/RHEL/CentOS/Fedora systems should only contain the information that is different from the parent eth0 device.
I agree with Michael Leahy.
/usr/share/doc/initscripts-*/sysconfig.txt says that the alias interfaces should not duplicate the information contained in the parent device.
From /usr/share/doc/initscripts-*/sysconfig.txt
Since when does an alias have to be on the same subnet? I use aliases all the time at work to create private “dev” VLANS with servers I SSH to directly (with a simple switch in between).
The ONBOOT parameter is not appropriate for a Virtual IP / IP Alias – you need to use the ONPARENT param instead.
HTH,
Steve Harper
Thanks I just managed to add a new network alias to my server. :) I also followed Steve’s advice about the onboot parameter.
For my centos5 this information was not sufficient. I’ve added a IP alias eth1:1 on a different subnet than eth1 with this ifcfg-eth1:1 file:
GATEWAY=194.xxx.xxx.xxx
TYPE=Ethernet
DEVICE=eth1:1
BOOTPROTO=none
NETMASK=255.255.255.0
IPADDR=194.xxx.xxx.xxx
USERCTL=no
IPV6INIT=no
ONPARENT=yes
PEERDNS=yes
This works fine with a:
service network restart
how many ip alias I can create in rhel 5, till now i have 64 alias of eth0 interface. I’m able to ping till 63th alias but not on 64 why’s that. I have found that in ubuntu we can create till 254 alias from one particular interface card.
any idea all the configuration are perfect and from sitting on the machine i’m able to ping myself on 64 alias.
but not from other machine which is in netwrok
thanks this help to my configure my network
Is there any limit for network aliases?
can i configure i.e. 512 ip addreses to one network card?
Stop taking all the ipv4 addresses for no reason!
IP address alias is simple option for adding multiple public IP address.
check # ip address help
Add IP Alias: ip addr add 122.122.122.122 dev eth1
Delete IP Alias: ip addr del 122.122.122.122/32 dev eth1
List IP Alias: ip addr show dev eth1