Task: assign several IP addresses to one network card.
We'll look at the solution using a network card named eth0 as an example.
Option 1: set addresses one after anotherIf the main config of your network card is in the file ifcfg-eth0 (the path stays the same: /etc/sysconfig/network-scripts), then the file with the first alias will be called ifcfg-eth0:0, the second one: ifcfg-eth0:1, and so on.
Here is an example of the main ifcfg-eth0 file
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.0.255
HWADDR=FE:16:3E:68:FC:FB
IPADDR=192.168.0.1
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
Here is an example of the ifcfg-eth0:0 file
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0:0
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=FE:16:3E:68:FC:FB
IPADDR=192.168.1.1
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
Here is the ifcfg-eth0:1 file
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0:1
BOOTPROTO=static
BROADCAST=192.168.2.255
HWADDR=FE:16:3E:68:FC:FB
IPADDR=192.168.2.1
NETMASK=255.255.255.0
NETWORK=192.168.2.0
ONBOOT=yes
As a result, eth0 will end up with 3 addresses:
- 192.168.0.1 (primary)
- 192.168.1.1
- 192.168.2.1
Option 2: set a range of addressesSame example as above. Here is the main ifcfg-eth0 file:
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
DEVICE=eth0
BOOTPROTO=static
BROADCAST=192.168.0.255
HWADDR=FE:16:3E:68:FC:FB
IPADDR=192.168.0.1
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
And here is the file declaring the range: ifcfg-eth0-range0
IPADDR_START=192.168.0.50
IPADDR_END=192.168.0.55
CLONENUM_START=1
As a result, we'll get the following IPs on eth0:
- 192.168.0.1
- 192.168.0.50
- 192.168.0.51
- 192.168.0.52
- 192.168.0.53
- 192.168.0.54
- 192.168.0.55
ApplyingAnd, as always, to apply the changes we restart the networking system:
$ sudo /etc/init.d/network restart
Comments