How you can have multiple ip addresses on a single nic in linux

Contents

# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:FA:F1:B7
inet addr:192.168..10 Bcast:192.168..255 Mask:255.255.255.
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:50 errors: dropped: overruns: frame:
Texas packets:76 errors: dropped: overruns: carrier:
collisions: txqueuelen:1000
RX bytes:6061 (5.9 KiB) Texas bytes:10824 (10.5 KiB)

lo Link encap:Local Loopback
inet addr:127…1 Mask:255…
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors: dropped: overruns: frame:
Texas packets:12 errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes:900 (900. b) Texas bytes:900 (900. b)

Here, “eth0” may be the first ethernet interface. The machines getting several ethernet cards have subsequent interfaces, “eth1”, “eth2”, and so forth. “lo” may be the local loopback interface. We’ll create alias of eth0 interface. However, let’s look into the configuration files of these interfaces.
The configuration files of these interfaces come in the “/etc/sysconfig/network-scripts/” directory. “ls -l /etc/sysconfig/network-scripts/” reveals these files.

# ls -l /etc/sysconfig/network-scripts/
total 380
-rw-r–r– 1 root root 191 Jul 3 19:01 ifcfg-eth0
-rw-r–r– 1 root root 254 March 13 2010 ifcfg-lo
lrwxrwxrwx 1 root root 20 Jul 3 03:51 ifdown -> ../../../sbin/ifdown
-rwxr-xr-x 1 root root 625 March 13 2010 ifdown-bnep
-rwxr-xr-x 1 root root 4573 March 13 2010 ifdown-eth
-rwxr-xr-x 1 root root 827 March 13 2010 ifdown-ippp
-rwxr-xr-x 1 root root 2149 March 13 2010 ifdown-ipsec
-rwxr-xr-x 1 root root 4473 March 13 2010 ifdown-ipv6
……

The very first file within this directory is ‘ifcfg-eth0’. This is actually the configuration apply for eth0 interface. Let’s look into the items in this file:

How you can have multiple ip addresses on a single nic in linux Then restart the network service

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Apple Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth0
IPADDR=192.168..10
NETMASK=255.255.255.
BOOTPROTO=static
HWADDR=08:00:27:FA:F1:B7
ONBOOT=yes
DHCP_HOSTNAME=redhat-server

Let’s take a look at these tags:

• DEVICE – The unit name goes here
• IPADDR is the need for Ip.
• NETMASK may be the subnet mask.
• If BOOTPROTO has value ‘static’, the interface is statically configured, i.e. Ip/subnet mask are added by hand. When the device takes address instantly, from DHCP server, its value ought to be ‘dhcp’. However in that situation, above two values, IPADDR and NETMASK is going to be missing.
• HWADDR may be the hardware or MAC address.
• If ONBOOT has value “yes”, the interface is going to be active, ready to go on boot. But it’ll be lower when the value is “no”.

Remaining values aren’t necessary. Any changes to those files is going to be persistent over boot. If you want your changes to become permanent, make alterations in the files of the directory (network-scripts), rather of utilizing ‘ifconfig’ command (to alter Ip).

How you can have multiple ip addresses on a single nic in linux UP LOOPBACK RUNNING
# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:FA:F1:B7
inet addr:192.168..10 Bcast:192.168..255 Mask:255.255.255.
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:50 errors: dropped: overruns: frame:
Texas packets:76 errors: dropped: overruns: carrier:
collisions: txqueuelen:1000
RX bytes:6061 (5.9 KiB) Texas bytes:10824 (10.5 KiB)

lo Link encap:Local Loopback
inet addr:127…1 Mask:255…
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors: dropped: overruns: frame:
Texas packets:12 errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes:900 (900. b) Texas bytes:900 (900. b)

Here, “eth0” may be the first ethernet interface. The machines getting several ethernet cards have subsequent interfaces, “eth1”, “eth2”, and so forth. “lo” may be the local loopback interface. We’ll create alias of eth0 interface. However, let’s look into the configuration files of these interfaces.
The configuration files of these interfaces come in the “/etc/sysconfig/network-scripts/” directory. “ls -l /etc/sysconfig/network-scripts/” reveals these files.

# ls -l /etc/sysconfig/network-scripts/
total 380
-rw-r–r– 1 root root 191 Jul 3 19:01 ifcfg-eth0
-rw-r–r– 1 root root 254 March 13 2010 ifcfg-lo
lrwxrwxrwx 1 root root 20 Jul 3 03:51 ifdown -> ../../../sbin/ifdown
-rwxr-xr-x 1 root root 625 March 13 2010 ifdown-bnep
-rwxr-xr-x 1 root root 4573 March 13 2010 ifdown-eth
-rwxr-xr-x 1 root root 827 March 13 2010 ifdown-ippp
-rwxr-xr-x 1 root root 2149 March 13 2010 ifdown-ipsec
-rwxr-xr-x 1 root root 4473 March 13 2010 ifdown-ipv6
……

The very first file within this directory is ‘ifcfg-eth0’. This is actually the configuration apply for eth0 interface. Let’s look into the items in this file:

How you can have multiple ip addresses on a single nic in linux Then restart the network service

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Apple Corporation 82540EM Gigabit Ethernet Controller
DEVICE=eth0
IPADDR=192.168..10
NETMASK=255.255.255.
BOOTPROTO=static
HWADDR=08:00:27:FA:F1:B7
ONBOOT=yes
DHCP_HOSTNAME=redhat-server

Let’s take a look at these tags:

• DEVICE – The unit name goes here
• IPADDR is the need for Ip.
• NETMASK may be the subnet mask.
• If BOOTPROTO has value ‘static’, the interface is statically configured, i.e. Ip/subnet mask are added by hand. When the device takes address instantly, from DHCP server, its value ought to be ‘dhcp’. However in that situation, above two values, IPADDR and NETMASK is going to be missing.
• HWADDR may be the hardware or MAC address.
• If ONBOOT has value “yes”, the interface is going to be active, ready to go on boot. But it’ll be lower when the value is “no”.

Remaining values aren’t necessary. Any changes to those files is going to be persistent over boot. If you want your changes to become permanent, make alterations in the files of the directory (network-scripts), rather of utilizing ‘ifconfig’ command (to alter Ip).

How you can have multiple ip addresses on a single nic in linux UP LOOPBACK RUNNING

Adding Virtual Interfaces

The virtual interfaces from the interface eth0 may have what they are called eth0:, eth0:1, eth0:2 and so forth. To include an interface, produce a corresponding file within the network-scripts directory. Now, let’s create an interface eth0:. To produce this alias, we’ll produce a file named “ifcfg-eth0:”:

I’ve produced this file using redirection, but you should use any editor you love to create this file:

# cat > /etc/sysconfig/network-scripts/ifcfg-eth0:
DEVICE=eth0:
IPADDR=192.168..20
NETMASK=255.255.255.
BOOTPROTO=static
HWADDR=08:00:27:FA:F1:B7
ONBOOT=yes

Observe that the device’s name is going to be altered to the specific virtual interface (eth0: here), and also the hardware address will stay the same (because physical device is identical). This really is everything is needed for allowing the alias. However these changes won’t be loaded towards the running system. Restart the networking as well as your new alias is able to be utilized:

# service network restart
Shutting lower interface eth0: [ OK ]

Shutting lower loopback interface: [ OK ]

Getting up loopback interface: [ OK ]

Getting up interface eth0: [ OK ]

# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:FA:F1:B7
inet addr:192.168..10 Bcast:192.168..255 Mask:255.255.255.
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:796 errors: dropped: overruns: frame:
Texas packets:480 errors: dropped: overruns: carrier:
collisions: txqueuelen:1000
RX bytes:74780 (73. KiB) Texas bytes:78183 (76.3 KiB)

eth0: Link encap:Ethernet HWaddr 08:00:27:FA:F1:B7
inet addr:192.168..20 Bcast:192.168..255 Mask:255.255.255.
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

lo Link encap:Local Loopback
inet addr:127…1 Mask:255…
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors: dropped: overruns: frame:
Texas packets:12 errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes:900 (900. b) Texas bytes:900 (900. b)

Using the ‘ifconfig’ command, the brand new (aliased) interfaces could be checked as proven within the output above. If you wish to bind another address to eth0, produce the alias eth0:1 similarly.

Temporarily adding multiple IP addresses on the NIC

You should use the ‘ifconfig’ command to include an Ip to some NIC. But, please be aware that this Ip won’t be available after rebooting the device. So, you should utilize the 2nd step for permanently adding the multiple IP addresses. Here, we think that you have a NIC having a static IP configured inside it. If we have to add two more IP addresses, say 192.168.1.25 and 192.168.1.26 for this interface, we are able to make this happen by executing the next instructions:

ifconfig eth0:1 192.168.1.25 netmask 255.255.255.
ifconfig eth0:2 192.168.1.26 netmask 255.255.255.

Adding an Ip range

To be able to add a variety of IP addresses to eth0 interface, say from 192.168.1.20 to 192.168.1.30, you have to create (update) the file /etc/sysconfig/network-scripts/ifcfg-eth0-range0 using the following data:

IPADDR_START=192.168.1.20
IPADDR_Finish=192.168.1.30
CLONENUM_START=
NETMASK=255.255.255.

Then restart the network service,

service network restart

Now, you’ll be able to determine the configured IP addresses using ‘ifconfig’ command.

Read Also:

  • Linux ifconfig Command Choices to Configure Interface
  • Using IP Command in Linux with Examples

Resourse: https://linoxide.com/linux-how-to/bind-ip-interface/

How to assign multiple IP addresses to a single Ethernet port or NIC of a PC

Video COMMENTS:
  • Pawan Kumar: How to add local area connection 2 is shows in your computer
  • idk2312: you could not possible make the intro any louder?