Linux一个主机多个ip,Linux一个主机配多个IP

首先我们在linux下查看该主机的IP地址:

#ifconfig

eth0      Link encap:Ethernet HWaddr 00:16:8d:B7:6A:E0

inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.252.0

inet6 addr: fd80::213:8eff:feb7:2ae0/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:7077 errors:0 dropped:0 overruns:0 frame:0

TX packets:54 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:654811 (639.4 KiB) TX bytes:6229 (6.0 KiB)

Interrupt:10 Base address:0xb800

这里我们只看到该主机只有一个IP地址,我们要在网卡eth0上再绑定另外一个IP,因为一般的机器它只有一张网卡,所以我们就在同一张网卡上进行多个IP的绑定。好了,我们开始做吧。

1.首先进入网卡的配置文件

#cd /etc/sysconfig/network-scripts

2.复制网卡eth0的配置文件

#cp ifcfg-eth0 ifcfg-eth0:0

3.修改ifcfg-eht0:0文件

#vi ifcfg-eth0:0

将其中的IP地址改为你的另外一个IP地址,比如我的修改如下:

DEVICE=eth0:0  #网卡的设置名称,要跟文件名一致

BOOTPROTO=static

HWADDR=00:16:8d:B7:6A:E0

IPADDR=192.168.1.112

NETMASK=255.255.252.0

GATEWAY=192.168.0.0

ONBOOT=yes

TYPE=Ethernet

注意的是,eth0:0的物理网卡地址必须要和eth0d物理网卡地址,即HWaddr要一致,因为是在同一网卡上绑定的多个IP。保存好后,我们就可以 重启网卡了.

4.重新启动网卡

/etc/init.d/network restart

5.启动后,再查看IP地址

#ifconfig

eth0      Link encap:Ethernet HWaddr 00:16:8d:B7:6A:E0

inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.252.0

inet6 addr: fd80::213:8eff:feb7:2ae0/64 Scope:Link

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

RX packets:7077 errors:0 dropped:0 overruns:0 frame:0

TX packets:54 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:654811 (639.4 KiB) TX bytes:6229 (6.0 KiB)

Interrupt:10 Base address:0xb800

eth0:0    Link encap:Ethernet HWaddr 00:16:8d:B7:6A:E0            inet addr:192.168.1.112 Bcast:192.168.1.255 Mask:255.255.252.0           UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1           Interrupt:10 Base address:0xb800     看看,机器是不是有两个IP地址了啊,呵呵,可以试着用另外一台机器ping下~~~ #ping 192.168.1.111 PING 192.168.1.111 (192.168.1.111) 56(84) bytes of data. 64 bytes from 192.168.1.111: icmp_seq=0 ttl=64 time=0.061 ms 64 bytes from 192.168.1.111: icmp_seq=1 ttl=64 time=0.048 ms 64 bytes from 192.168.1.111: icmp_seq=2 ttl=64 time=0.052 ms #ping 192.168.1.112 PING 192.168.1.112 (192.168.1.112) 56(84) bytes of data. 64 bytes from 192.168.1.112: icmp_seq=0 ttl=64 time=0.063 ms 64 bytes from 192.168.1.112: icmp_seq=1 ttl=64 time=0.055 ms 64 bytes from 192.168.1.112: icmp_seq=2 ttl=64 time=0.055 ms

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值