分享

一张网卡配置一个以上的ip

 农夫子oice 2007-04-25

查看完全版本 : 一张网卡配置一个以上的ip


walker
04-11-22, 17:30
一张网卡设置两个IP[北南]

前言:这是我以RedHat 7.3为例来说明的,有可能系统版本不同,不过我觉得大同小异吧。哈。。。

1.进入目录:
[root@Linuxsir root]# cd /etc/sysconfig/network-scripts/

2:ifcfg-eh0:0中的eh0:0是网卡的代号,当然你也可以用eh0:1之类的,随你喜欢怎么弄,但在eh0:X之前必须有ifcfg,也就是下面这种形式的,我们以eh0:0为例。

[root@Linuxsir root]#cp ifcfg-eth0 ifcfg-eth0:0

3,编辑ifcfg-eth0:0
[root@Linuxsir root]# vi ifcfg-eth0:0

ifcfg-eth0:0里面有这样的内容,你可以这样设置,然后IP可以自己设置了。象我这样设置也一样。

# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
USERCTL=‘no‘
NETMASK=‘255.255.255.0‘ -》子掩码
BOOTPROTO=‘static‘ -》协议
DEVICE=‘eth0:0‘ -》虚拟网卡的代号
IPADDR=‘192.168.0.9‘ -》我自己设定的IP
TYPE=‘Ethernet‘
onBOOT=‘yes‘ -》是否开机激活
NETWORK=‘192.168.0.0‘ -》网域
BROADCAST=‘192.168.0.255‘ -》广播

4.保存退出,然后运行如下的命令,来激活虚拟的网卡。
[root@Linuxsir root]# ifup eh0:0
5.我们来查看我们虚拟的网卡是不是激活了,用ifconfig,也就是下面这样的。

[root@Linuxsir network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:E0:4C:00:C9:05
inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:180 (180.0 b) TX bytes:7157 (6.9 Kb)
Interrupt:11 Base address:0x2000

eth0:0 Link encap:Ethernet HWaddr 00:E0:4C:00:C9:05
inet addr:192.168.0.9 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:11 Base address:0x2000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:12 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:846 (846.0 b) TX bytes:846 (846.0 b)

6.ping一下IP,就能知道我们做的是不是成功了。

[root@Linuxsir network-scripts]# ping 192.168.0.9
PING 192.168.0.9 (192.168.0.9) from 192.168.0.9 : 56(84) bytes of data.
64 bytes from 192.168.0.9: icmp_seq=1 ttl=255 time=0.097 ms
64 bytes from 192.168.0.9: icmp_seq=2 ttl=255 time=0.043 ms
64 bytes from 192.168.0.9: icmp_seq=3 ttl=255 time=0.043 ms
64 bytes from 192.168.0.9: icmp_seq=4 ttl=255 time=0.044 ms
64 bytes from 192.168.0.9: icmp_seq=5 ttl=255 time=0.043 ms

--- 192.168.0.9 ping statistics ---
14 packets transmitted, 14 received, 0% loss, time 12996ms
rtt min/avg/max/mdev = 0.039/0.046/0.097/0.016 ms

[root@Linuxsir network-scripts]# ping 192.168.0.1
PING 192.168.0.1 (192.168.0.1) from 192.168.0.1 : 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=255 time=0.069 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=255 time=0.042 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=255 time=0.040 ms
64 bytes from 192.168.0.1: icmp_seq=4 ttl=255 time=0.042 ms

--- 192.168.0.1 ping statistics ---
7 packets transmitted, 7 received, 0% loss, time 5995ms
rtt min/avg/max/mdev = 0.040/0.046/0.069/0.009 ms



faint:
Debian下也不错。如:
Debian下一个网卡绑定多个ip的方法(NetDC)
修改/etc/network/interfaces
auto eth0
iface eth0 inet static
address 172.16.3.123
netmask 255.255.255.0
network 172.16.3.0
broadcast 172.16.3.255
gateway 172.16.3.1

auto eth0:1
iface eth0:1 inet static
address 10.16.3.123
netmask 255.255.0.0
network 10.16.0.0
broadcast 10.16.255.255
修改/etc/network/ifstate
lo=lo
eth0=eth0
eth0:1=eth0:1
然后/etc/init.d/networking restart就可以了。

来自:linuxsir

apache
04-11-23, 17:51
命令使用方法:
[root@vhost root]# ip address help
Usage: ip addr {add|del} IFADDR dev STRING
ip addr {show|flush} [ dev STRING ] [ scope SCOPE-ID ]
[ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ]
IFADDR := PREFIX | ADDR peer PREFIX
[ broadcast ADDR ] [ anycast ADDR ]
[ label STRING ] [ scope SCOPE-ID ]
SCOPE-ID := [ host | link | global | NUMBER ]
FLAG-LIST := [ FLAG-LIST ] FLAG
FLAG := [ permanent | dynamic | secondary | primary |
tentative | deprecated ]
[root@vhost root]#
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多