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:
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 shoshould 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.
Caution: alias interfaces do not support DHCP.
A clone interface configuration file shocould use the following naming convention:ifcfg-<if-name>
-<clone-name>
.
While an alias file allows multiple addresses for an existing
Interface, a clone file is used to specify additional options for
Interface. For example, a standard DHCP Ethernet interface calledeth0
, May look similar to this:
DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp
Since the default value forUSERCTL
Directive isno
If it is not specified, users cannot bring this interface up and down.
To give users the ability to control the interface, create a clone
Copyingifcfg-eth0
Toifcfg-eth0-user
And add the following lineifcfg-eth0-user
:
USERCTL=yes
This way a user can bring upeth0
Interface using/sbin/ifup eth0-user
Command because the configuration options fromifcfg-eth0
Andifcfg-eth0-user
Are combined. While this is a very basic example, this method can be used with a variety of options and interfaces.
The easiest way to create alias and clone interface configuration files is to use the graphicalNetwork Administration Tool. For more information on using this tool, refer to chapter 15,Network Configuration. Or the following:
15.11. device aliases
Device aliases
Are Virtual Devices associated with the same physical hardware,
They can be activated at the same time to have different IP addresses.
They are commonly represented as the device name followed by a colon
And a number (for example, eth0: 1). They are useful if you want to have
Multiple IP addresses for a system that only has one network card.
After Authentication ing the Ethernet device-sucheth0
-To use a static IP address (DHCP does not work with aliases), go toDevicesTab and clickNew. Select the ethernet card to configure with an alias, set the static IP address for the alias, and clickApplyTo create it. Since a device already exists for the ethernet card, the one just created is the alias, sucheth0:1
.
Warning
If you are using ing an Ethernet device to have an alias, neither
Device nor the alias can be configured to use DHCP. You must configure
The IP addresses manually.
Figure 15.22, "network device alias example" shows an example of one alias foreth0
Device. Noticeeth0:1
Device-the First aliaseth0
. The Second aliaseth0
Wocould have the device nameeth0:2
,
And so on. To modify the settings for the device alias, such as whether
To activate it at boot time and the alias number, select it from
List and clickEditButton.
[D]
Figure 15.22. network device alias example
Select the alias and clickActivateButton to activate the alias. If you have configured multiple profiles, select which profiles in which to include it.
To verify that the alias has been activated, use the command/sbin/ifconfig
. The output shocould show the device and the device alias with different IP addresses: