Linux单网卡绑定多IP

来源:百度文库 编辑:神马文学网 时间:2024/04/25 01:36:52
方法一在/etc/sysconfig/network-scripts/下创建ifcfg-eth0:x网卡配置文件,通过此配置文件来绑定IP,最多可绑定255个IP。[root@info ~]# cd /etc/sysconfig/network-scripts/[root@info network-scripts]# pwd/etc/sysconfig/network-scripts[root@info network-scripts]# cp ifcfg-eth0 ifcfg-eth0:1[root@info network-scripts]# vi ifcfg-eth0:1DEVICE=eth0:1 #设备名称ONBOOT=yesBOOTPROTO=staticIPADDR=172.16.0.100 #绑定IP地址NETMASK=255.255.0.0GATEWAY=172.16.1.1 重启网路服务[root@info network-scripts]# service network restart正在关闭接口 eth0:                                        [  确定  ]关闭环回接口:                                             [  确定  ]设置网络参数:                                             [  确定  ]弹出环回接口:                                             [  确定  ]弹出界面 eth0:                                            [  确定  ]弹出界面 eth0.tmp:                                        [  确定  ] [root@info network-scripts]# ifconfigeth0      Link encap:Ethernet  HWaddr 00:0C:29:84:F8:33            inet addr:192.168.1.90  Bcast:192.168.1.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe84:f833/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:1177 errors:0 dropped:0 overruns:0 frame:0          TX packets:965 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:92683 (90.5 KiB)  TX bytes:92726 (90.5 KiB)          Interrupt:185 Base address:0x2000  eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:84:F8:33            inet addr:172.16.0.100  Bcast:172.16.255.255  Mask:255.255.0.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          Interrupt:185 Base address:0x2000  方法二使用ifconfig 设备名 IP地址  广播地址 子网掩码来绑定IP,缺陷是当系统重启时,ifconfig绑定的参数会丢失,需手工重新配置。但可以把配置参数加入启动文件中,让其自动运行。[root@info network-scripts]# ifconfig eth0:2 10.0.0.100 netmask 255.0.0.0[root@info network-scripts]# vi /etc/rc.d/rc.local  #!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you dont# want to do the full Sys V style init stuff. touch /var/lock/subsys/localifconfig eth0:2 10.0.0.100 netmask 255.0.0.0 [root@info ~]# ifconfig eth0:2eth0:2    Link encap:Ethernet  HWaddr 00:0C:29:84:F8:33            inet addr:10.0.0.100  Bcast:10.255.255.255  Mask:255.0.0.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          Interrupt:185 Base address:0x2000