配置虚拟主机时有一种方式是在一块网卡上绑定多个IP,操作如下:
首先用ifconfig查看物理网卡
[root@devserver1 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:E0:4C:F1:5B:E3
inet addr:192.168.0.66 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::2e0:4cff:fef1:5be3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:136875410 errors:1514 dropped:0 overruns:0 frame:1
TX packets:33575076 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:850013826 (810.6 MiB) TX bytes:550942326 (525.4 MiB)
Interrupt:177 Base address:0x8000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:9013362 errors:0 dropped:0 overruns:0 frame:0
TX packets:9013362 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2146802575 (1.9 GiB) TX bytes:2146802575 (1.9 GiB)
其中lo是本地回环,eh开头的是物理网卡,我只有一块网卡,所以显示eth0。
那么现在我们在eth0上绑定其他IP地址
[root@devserver1 ~]# ifconfig eth0:1 192.168.0.201 netmask 255.255.255.0 up [root@devserver1 ~]# route add -host 192.168.0.201 dev eth0:1 [root@devserver1 ~]# [root@devserver1 ~]# ifconfig eth0:2 192.168.0.202 netmask 255.255.255.0 up [root@devserver1 ~]# route add -host 192.168.0.202 dev eth0:2
eth0:n 这里的n可以自己随便设置
route 为新地址添加路由并且绑定在相应的eth0:n上
ok,现在在其他机器上ping一下,应该已经通了:)
注意:
1.这里绑定的其他IP,会在机器重启时消失,如果想永久绑定,就需要在开机时写一个shell,把上边的shell贴在:
(/etc/rc.local)文件里就OK了:)
2.删除绑定IP:
[root@localhost etc]# ifconfig eth0:1 down [root@localhost etc]# ifconfig eth0:2 down
3.删除路由(如果已经删除绑定IP,路由会自动消失)
[root@devserver1 ~]# route del 192.168.0.201 dev eth0:1 [root@devserver1 ~]# route del 192.168.0.202 dev eth0:2
附加:
如何启动/禁用网卡
启用
ifconfig eth0 up
禁用
ifconfig eth0 down
给网卡赋予静态ip
ifconfig eth0 192.168.1.101
本文介绍如何在同一块物理网卡上绑定多个IP地址的方法,并提供详细步骤。包括使用ifconfig命令进行IP绑定及解除绑定,route命令添加和删除路由。同时说明了如何确保IP绑定在系统重启后仍然有效。
1244

被折叠的 条评论
为什么被折叠?



