About IP Alias in Linux (Esp. CentOS)
2008-11-17 18:18
281 查看
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.
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:
Verify alias is up and running using following command:
# 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.
Append text as follows:
Save and close the file. Restart the network:
Open file /etc/sysconfig/network-scripts/ifcfg-eth0:0 using vi text editor:
Find entry that read as follows:
DEVICE=eth0
Replace with:
DEVICE=eth0:0
Find entry that read as follows:
Replace it with your actual IP address:
At the end your file should like as follows:
Open file /etc/sysconfig/network-scripts/ifcfg-eth0 and make sure file does not have a GATEWAY= entry:
Find the entry that read as follows:
Remove or comment it out by prefixing # (hash) :
Save the file. Add the GATEWAY= to your /etc/sysconfig/network:
Append or modify GATEWAY entry:
Save the file. Reboot the system or run the following command:
OR
Append following code from 202.54.112.120 to 202.54.112.140:
Save and close the file.
Caution: Alias interfaces do not support DHCP.
A clone interface configuration file should use the following naming convention:
While an alias file allows multiple addresses for an existing
interface, a clone file is used to specify additional options for an
interface. For example, a standard DHCP Ethernet interface called
[/code]
Since the default value for the
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 by
copying
[/code]
This way a user can bring up the
The easiest way to create alias and clone interface configuration files is to use the graphical Network Administration Tool. For more information on using this tool, refer to Chapter 15, Network Configuration. or the following:
are virtual devices associated with the same physical hardware, but
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 configuring the Ethernet device —such as
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 for the
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 the
list and click the Edit button.
![](http://www.centos.org/docs/5/html/5.1/Deployment_Guide/images/neat-aliases.png)
[D]
Figure 15.22. Network Device Alias Example
Select the alias and click the Activate button 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
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.
Caution: Alias interfaces do not support DHCP.
A clone interface configuration file should 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 an
interface. For example, a standard DHCP Ethernet interface called
eth0, may look similar to this:
DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp
[/code]
Since the default value for the
USERCTLdirective is
no
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 by
copying
ifcfg-eth0to
ifcfg-eth0-userand add the following line to
ifcfg-eth0-user:
USERCTL=yes
[/code]
This way a user can bring up the
eth0interface using the
/sbin/ifup eth0-usercommand because the configuration options from
ifcfg-eth0and
ifcfg-eth0-userare 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 graphical Network Administration Tool. For more information on using this tool, refer to Chapter 15, Network Configuration. or the following:
15.11. Device Aliases
Device aliasesare virtual devices associated with the same physical hardware, but
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 configuring the Ethernet device —such as
eth0—to use a static IP address (DHCP does not work with aliases), go to the Devices tab and click New. Select the Ethernet card to configure with an alias, set the static IP address for the alias, and click Apply to create it. Since a device already exists for the Ethernet card, the one just created is the alias, such as
eth0:1.
Warning
If you are configuring an Ethernet device to have an alias, neither thedevice 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 for the
eth0device. Notice the
eth0:1device — the first alias for
eth0. The second alias for
eth0would have the device name
eth0: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 the
list and click the Edit button.
![](http://www.centos.org/docs/5/html/5.1/Deployment_Guide/images/neat-aliases.png)
[D]
Figure 15.22. Network Device Alias Example
Select the alias and click the Activate button 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 should show the device and the device alias with different IP addresses:
相关文章推荐
- CentOS 6.5/Linux 重启网卡报错 Determining if ip address x.x.x.x is already in use
- about Q&A in installing linux[centos6,7]
- How To Use Ip Command In Linux with Examples
- fw: IP bonding in Linux.
- 【linux】centos6.9设置etc0网卡开机自动获取ip
- 《生活在Linux中》之:prefer function to alias in Bash
- Linux(CentOS)下,DNAT和SNAT(分享IP)
- 2010-03-30 ipip.c in linux
- Linux学习之CentOS(二十九)--Linux网卡高级命令、IP别名及多网卡绑定
- Somethings about the Process in the Linux
- [完]Linux CentOS IP配置
- linux 虚拟机centos64位_6.5+VM10 主机是固定IP局域网设置代理上网,虚机设置固定ip 图文详细步骤
- Linux centos系统的IP设置配置方法
- Quick Tip: Configure Static IP in Centos 6.5
- Editing your DNS in Linux/CentOS | Dynamic Hosting Blog
- Centos(linux)系统 ip命令使用方法
- Install Linux Kernel 4.10 In CentOS and Ubuntu
- Setting a Static IP in a CentOS 7 Minimal Installation
- 【Linux】CentOS设置静态IP(非动态获取IP)
- [Linux] - CentOS IP设置方法