Linux单网卡绑定多IP

Linux单网卡绑定多IP
收藏人:gnulinux
2010-12-29 | 阅:  转:  |  分享 
  |     来源
 
  
 
方法一
在/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:1
DEVICE=eth0:1 #设备名称
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.0.100 #绑定IP地址
NETMASK=255.255.0.0
GATEWAY=172.16.1.1
 
重启网路服务
[root@info network-scripts]# service network restart
正在关闭接口 eth0:                                        [  确定  ]
关闭环回接口:                                             [  确定  ]
设置网络参数:                                             [  确定  ]
弹出环回接口:                                             [  确定  ]
弹出界面 eth0:                                            [  确定  ]
弹出界面 eth0.tmp:                                        [  确定  ]
 
[root@info network-scripts]# ifconfig
eth0      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地址来架运行多个HTTPD服务器,就要用到虚拟地址;这样就省却了同一个IP地址,如果开设两个的HTTPD服务器时,要指定端口号。 

虚拟网络接口指的是为一个网络接口指定多个IP地址,虚拟接口是这样的 eth0:0 、 eth0:1、eth0:2 ... .. eth1N。当然您为eth1 指定多个IP地址,也就是 eth1:0、eth1:1、eth1:2 ... ...以此类推; 
ifconfig eth1:0 192.168.1.250 hw ether 00:11:00:00:11:44 netmask 255.255.255.0 broadcast 192.168.1.255 up
ifconfig eth1:1 192.168.1.249 hw ether 00:11:00:00:11:55 netmask 255.255.255.0 broadcast 192.168.1.255 up
注意:指定时,要为每个虚拟网卡指定不同的物理地址; 


使用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/local
ifconfig eth0:2 10.0.0.100 netmask 255.0.0.0
 
[root@info ~]# ifconfig eth0:2
eth0: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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值