环境: RHEL6.4
需求: Linux一块网卡添加多个IP地址
一、临时生效
- 1.1 网卡eth0添加一个IP地址
- 1.2 修改eth0:0的广播地址
二、永久生效
- 2.1 编辑ifcfg-eth0:0
- 2.2 重启网卡生效配置
当前eth0的配置:
# ifconfig
eth0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:192.168.99.159 Bcast:192.168.99.255 Mask:255.255.255.0
inet6 addr: fe80::282e:beff:fecf:8cdc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32955247 errors:0 dropped:0 overruns:0 frame:0
TX packets:3800040 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15964502776 (14.8 GiB) TX bytes:11315742252 (10.5 GiB)
Interrupt:247
一、临时生效
1.1 网卡eth0添加一个IP地址
ifconfig eth0 add 10.10.10.159
查看:
# ifconfig -a
eth0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:192.168.99.159 Bcast:192.168.99.255 Mask:255.255.255.0
inet6 addr: fe80::282e:beff:fecf:8cdc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32958394 errors:0 dropped:0 overruns:0 frame:0
TX packets:3800101 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15965401503 (14.8 GiB) TX bytes:11315752846 (10.5 GiB)
Interrupt:247
eth0:0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:10.10.10.159 Bcast:192.168.99.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:247
发现多了一个基于eth0的eth0:0的虚拟接口。
1.2 修改eth0:0的广播地址
ifconfig eth0:0 broadcast 10.10.10.255
查看:
# ifconfig -a
eth0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:192.168.99.159 Bcast:192.168.99.255 Mask:255.255.255.0
inet6 addr: fe80::282e:beff:fecf:8cdc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32959543 errors:0 dropped:0 overruns:0 frame:0
TX packets:3800126 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15965717592 (14.8 GiB) TX bytes:11315758056 (10.5 GiB)
Interrupt:247
eth0:0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:10.10.10.159 Bcast:10.10.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:247
成功修改了eth0:0的广播地址。
二、永久生效
2.1 编辑ifcfg-eth0:0
配置文件在/etc/sysconfig/network-scripts/
路径下。
# cd /etc/sysconfig/network-scripts/
# more ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.99.159
NETMASK=255.255.255.0
# more ifcfg-eth0:0
DEVICE=eth0:0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.10.10.159
NETMASK=255.255.255.0
如果还想添加IP地址,可以同理编辑ifcfg-eth0:1
文件.
2.2 重启网卡生效配置
2.2.1 可以重启整个网络服务:
service network restart
2.2.2 也可针对eth0网卡,关闭再启动:
ifdown eth0
ifup eth0
2.2.3 最后看eth0网卡信息如下:
ifconfig查看eth0的网卡信息:
# ifconfig
eth0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:192.168.99.159 Bcast:192.168.99.255 Mask:255.255.255.0
inet6 addr: fe80::282e:beff:fecf:8cdc/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:32989071 errors:0 dropped:0 overruns:0 frame:0
TX packets:3800770 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15974202540 (14.8 GiB) TX bytes:11315842294 (10.5 GiB)
Interrupt:247
eth0:0 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:10.10.10.159 Bcast:10.10.10.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:247
eth0:1 Link encap:Ethernet HWaddr 2A:2E:BE:CF:8C:DC
inet addr:10.11.11.159 Bcast:10.11.11.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:247