Multiple IP addresses (or multiple IP addresses) of a single Nic in Linux

Source: Internet
Author: User

RedHat in Linux

Modify IP Address:
Edit file/etc/sysconfig/network-scripts/ifcfg-eth0
Device = eth0 // device name, do not modify
Bootproto = static // do not modify
Broadcast = 10.10.22.255 // broadcast address, which is generally the last IP address of the network segment
Ipaddr = 10.10.22.145 // ip address
Netmask = 255.255.255.0 // Subnet Mask
Network = 10.10.22.0 // CIDR block address
Onboot = Yes // do not modify
Type = Ethernet // do not modify
Note: The ifcfg-eth0 is the first Nic, The ifcfg-eth1 is the second Nic, and so on

Add IP Address:
You can recompile a file named/etc/sysconfig/network-scripts/ifcfg-eth0: 0
You can also add it directly in/etc/sysconfig/network-scripts/ifcfg-eth0 (but the device eth0 must have)
Device = eth0: 0 // device name, do not modify
Bootproto = static // do not modify
Broadcast = 10.10.33.255 // broadcast address, which is generally the last IP address of the network segment
Ipaddr = 10.10.33.145 // ip address
Netmask = 255.255.255.0 // Subnet Mask
Network = 10.10.33.0 // network segment address
Onboot = Yes // do not modify
Type = Ethernet // do not modify

And so on. If you add another IP address, add the following Configuration:
Device = eth0: 1 // device name, do not modify
Bootproto = static // do not modify
Broadcast = 10.10.44.255 // broadcast address, which is generally the last IP address of the network segment
Ipaddr = 10.10.44.145 // ip address
Netmask = 255.255.255.0 // Subnet Mask
Network = 10.10.44.0 // CIDR block address
Onboot = Yes // do not modify
Type = Ethernet // do not modify

Similarly, if you are on the second Nic, you need to add:
Device = eth1: 0 // device name, do not modify
Bootproto = static // do not modify
Broadcast = 10.10.33.255 // broadcast address, which is generally the last IP address of the network segment
Ipaddr = 10.10.33.145 // ip address
Netmask = 255.255.255.0 // Subnet Mask
Network = 10.10.33.0 // network segment address
Onboot = Yes // do not modify
Type = Ethernet // do not modify

 

Add the Default Gateway:
Note that only one machine can have one default gateway; otherwise, a specific routing method should be provided.
Add one to the related device configuration. For example, in the above configuration, add a default gateway to the first IP address of the first NIC:
Device = eth0
Bootproto = static
Broadcast = 10.10.22.255
Ipaddr = 10.10.22.145
Netmask = 255.255.255.0
Network = 10.10.22.0
Onboot = Yes
Type = Ethernet
Gateway = 10.10.22.3

After the modification, You need to restart the machine or network to make the modification take effect.
The method to restart the machine is: reboot
The method to restart the network is: Service Network restart

The preceding method adds IP addresses statically, that is, it is still effective after the machine is restarted.

Dynamic Method
Note: All operations use the root user.
Modify IP Address:
Ifconfig eth0 10.10.22.145
Change the IP address of the first ENI to 10.10.22.145.

Add IP Address:
Ifconfig eth0 add 10.10.33.145 // Add an IP address
Ifconfig eth0: 0 broadcast 10.10.33.255 // modify the broadcast address of the added IP Address

Add another IP Address:
Ifconfig eth0: 0 add 10.10.44.145
Ifconfig eth0: 0: 1 Broadcast 10.10.44.255 // modify the broadcast address of the added IP Address
Do not perform the following operations:
Ifconfig eth0 add 10.10.44.145
In this way, the added ip10.33.145 is changed to 10.10.44.145.

Add another IP Address:
Ifconfig eth0: 0: 1 add 10.10.55.145
Ifconfig eth0: 0: 1: 1 Broadcast 10.10.55.255 // modify the broadcast address of the added IP Address

 

Debian

Http://wiki.debian.org/NetworkConfiguration

1) Debian Method for binding multiple IP addresses to the next Nic and adding routes

Modify/etc/Network/interfaces
Auto eth0
Iface eth0 Inet static
Address 172.16.3.123
Netmask 255.255.255.0
Network 172.16.3.0
Broadcast 172.16.3.255
Gateway 172.16.3.1

Auto eth0: 1
Iface eth0: 1 Inet static
Address 10.16.3.123
Netmask 255.255.0.0
Network 10.16.0.0
Broadcast 10.16.0000255
Modify/etc/Network/ifstate
Lo = Lo
Eth0 = eth0
Eth0: 1 = eth0: 1
Then/etc/init. d/networking restart.

 

Add a route entry to Debian,
Method 1: Modify/etc/Network/interfaces
Code:
Auto eth0
Iface eth0 Inet static
Address 172.16.3.222
Netmask 255.255.0.0
Network 172.16.0.0
Broadcast 172.16.0000255
Gateway 172.16.2.1
Up Route add-net 192.168.0.0 netmask 255.255.255.0 GW 172.16.0.1
Down Route del-net 192.168.0.0 netmask 255.255.255.0 GW 172.16.0.1

Method 2: create a simple script file under the/etc/Network/if-up.d directory, such as static-route $ (remember to end with the $ symbol, otherwise, a run-parts will run to tell you something.) The script is the simplest, for example:
Code:
#! /Bin/bash
Route add-net 192.168.0.0 netmask 255.255.255.0 GW 172.16.0.1
Hey, you can also guess the role of other directories under the/etc/Network/directory.
I found that in Debian, this route setting is only a simple application of its configuration files. You can do more complex applications.

2) It is also very easy to configure different IP addresses for multiple NICs.

Copy all ipsettings under eth0, copy them to the interface file, and change eth0 to eth1. And so on. Restart the network.

Host Name that cannot be parsed, modify/etc/hosts

---------------------------

The following is an example of Debian's automatic IP address acquisition from the DHCP server:

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)# The loopback interfaceauto loiface lo inet loopback# The first network card - this entry was created during the Debian installation# (network, broadcast and gateway are optional)auto eth0iface eth0 inet dhcp
----------------------
Using DHCP to automatically configure the interface

If you're just using DHCP then all you need is something like:

    auto eth0    allow-hotplug eth0    iface eth0 inet dhcp
Processing the interface manually

If you're using ing it manually then something like this will set the Default Gateway (Network, broadcast and gateway are optional ):

    auto eth0    iface eth0 inet static        address 192.168.0.7        netmask 255.255.255.0        gateway 192.168.0.254

If you want to add an IPv6 address, too,AppendSomething like:

    iface eth0 inet6 static        address 2001:db8::c0ca:1eaf        netmask 64        gateway 2001:db8::1ead:ed:beef
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.