子网卡,具体说就是一快网卡上配置多个IP地址。
它的实现细节,将会在接下来的内容中展开。
首先看看我的Linux的当前网络环境:
[root@mysql-1 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:97:5C:02 inet addr:192.168.111.128 Bcast:192.168.111.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe97:5c02/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:51 errors:0 dropped:0 overruns:0 frame:0 TX packets:41 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4600 (4.4 KiB) TX bytes:3294 (3.2 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:97:5C:0C inet addr:192.168.111.162 Bcast:192.168.111.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe97:5c0c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:38 errors:0 dropped:0 overruns:0 frame:0 TX packets:44 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4927 (4.8 KiB) TX bytes:5043 (4.9 KiB) 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:65536 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:960 (960.0 b) TX bytes:960 (960.0 b) [root@mysql-1 ~]# [root@mysql-1 ~]# ls -al /sys/class/net/ total 0 drwxr-xr-x 2 root root 0 Aug 31 10:00 . drwxr-xr-x 43 root root 0 Aug 31 10:00 .. lrwxrwxrwx 1 root root 0 Aug 31 10:00 eth0 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:00.0/net/eth0 lrwxrwxrwx 1 root root 0 Aug 31 10:00 eth1 -> ../../devices/pci0000:00/0000:00:11.0/0000:02:03.0/net/eth1 lrwxrwxrwx 1 root root 0 Aug 31 10:00 lo -> ../../devices/virtual/net/lo [root@mysql-1 ~]# [[root@mysql-1 ~]# cd /etc/sysconfig/network-scripts/ [root@mysql-1 network-scripts]# ls ifcfg-eth0 ifdown-ib ifdown-routes ifup-eth ifup-plusb ifup-wireless ifcfg-lo ifdown-ippp ifdown-sit ifup-ib ifup-post init.ipv6-global ifcfg-System_eth1 ifdown-ipv6 ifdown-tunnel ifup-ippp ifup-ppp net.hotplug ifdown ifdown-isdn ifup ifup-ipv6 ifup-routes network-functions ifdown-bnep ifdown-post ifup-aliases ifup-isdn ifup-sit network-functions-ipv6 ifdown-eth ifdown-ppp ifup-bnep ifup-plip ifup-tunnel [root@mysql-1 network-scripts]#
这里,打算给第一块网卡【eth0】配置两个子网:
[root@mysql-1 network-scripts]# vi ifcfg-eth0:0 [root@mysql-1 network-scripts]# vi ifcfg-eth0:1 [root@mysql-1 network-scripts]# [root@mysql-1 network-scripts]# ls ifcfg-eth0 ifdown-eth ifdown-routes ifup-ib ifup-ppp network-functions ifcfg-eth0:0 ifdown-ib ifdown-sit ifup-ippp ifup-routes network-functions-ipv6 ifcfg-eth0:1 ifdown-ippp ifdown-tunnel ifup-ipv6 ifup-sit ifcfg-lo ifdown-ipv6 ifup ifup-isdn ifup-tunnel ifcfg-System_eth1 ifdown-isdn ifup-aliases ifup-plip ifup-wireless ifdown ifdown-post ifup-bnep ifup-plusb init.ipv6-global ifdown-bnep ifdown-ppp ifup-eth ifup-post net.hotplug [root@mysql-1 network-scripts]# [root@mysql-1 network-scripts]# cat ifcfg-eth0:0 DEVICES=eth0:0 BOOTPROTO=static IPADDR=192.168.111.151 NETMASK=255.255.255.0 ONBOOT=yes [root@mysql-1 network-scripts]# cat ifcfg-eth0:1 DEVICES=eth0:1 BOOTPROTO=static IPADDR=192.168.111.152 NETMASK=255.255.255.0 ONBOOT=yes [root@mysql-1 network-scripts]#
重启网络服务【network】:
[root@mysql-1 ~]# service NetworkManager status NetworkManager (pid 1598) is running... [root@mysql-1 ~]# [root@mysql-1 ~]# service NetworkManager stop Stopping NetworkManager daemon: [ OK ] [root@mysql-1 ~]# [root@mysql-1 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:97:5C:02 inet addr:192.168.111.128 Bcast:192.168.111.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe97:5c02/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:619 errors:0 dropped:0 overruns:0 frame:0 TX packets:368 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:52510 (51.2 KiB) TX bytes:51499 (50.2 KiB) eth1 Link encap:Ethernet HWaddr 00:0C:29:97:5C:0C inet addr:192.168.111.162 Bcast:192.168.111.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe97:5c0c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:76 errors:0 dropped:0 overruns:0 frame:0 TX packets:77 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:9301 (9.0 KiB) TX bytes:7287 (7.1 KiB) 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:65536 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:960 (960.0 b) TX bytes:960 (960.0 b) [root@mysql-1 ~]# [root@mysql-1 ~]# service network restart Shutting down interface System_eth1: [ OK ] Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface System_eth1: Determining if ip address 192.168.111.162 is already in use for device eth1... [ OK ] Bringing up interface eth0: Determining if ip address 192.168.111.128 is already in use for device eth0... Determining if ip address 192.168.111.151 is already in use for device eth0... Determining if ip address 192.168.111.152 is already in use for device eth0... [ OK ] [root@mysql-1 ~]# [root@mysql-1 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:97:5C:02 inet addr:192.168.111.128 Bcast:192.168.111.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe97:5c02/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:683 errors:0 dropped:0 overruns:0 frame:0 TX packets:421 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:57554 (56.2 KiB) TX bytes:57747 (56.3 KiB) eth0:0 Link encap:Ethernet HWaddr 00:0C:29:97:5C:02 inet addr:192.168.111.151 Bcast:192.168.111.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 eth0:1 Link encap:Ethernet HWaddr 00:0C:29:97:5C:02 inet addr:192.168.111.152 Bcast:192.168.111.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 eth1 Link encap:Ethernet HWaddr 00:0C:29:97:5C:0C inet addr:192.168.111.162 Bcast:192.168.111.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe97:5c0c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:114 errors:0 dropped:0 overruns:0 frame:0 TX packets:109 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12071 (11.7 KiB) TX bytes:11707 (11.4 KiB) 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:65536 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:960 (960.0 b) TX bytes:960 (960.0 b) [root@mysql-1 ~]#
如上,这样,子网卡就配好了。
测试下:
C:\Users\adamhuan>ping -n 2 192.168.111.128 正在 Ping 192.168.111.128 具有 32 字节的数据: 来自 192.168.111.128 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.111.128 的回复: 字节=32 时间<1ms TTL=64 192.168.111.128 的 Ping 统计信息: 数据包: 已发送 = 2,已接收 = 2,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 0ms,最长 = 0ms,平均 = 0ms C:\Users\adamhuan> C:\Users\adamhuan>ping -n 3 192.168.111.151 正在 Ping 192.168.111.151 具有 32 字节的数据: 来自 192.168.111.151 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.111.151 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.111.151 的回复: 字节=32 时间<1ms TTL=64 192.168.111.151 的 Ping 统计信息: 数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 0ms,最长 = 0ms,平均 = 0ms C:\Users\adamhuan> C:\Users\adamhuan>ping -n 3 192.168.111.152 正在 Ping 192.168.111.152 具有 32 字节的数据: 来自 192.168.111.152 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.111.152 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.111.152 的回复: 字节=32 时间<1ms TTL=64 192.168.111.152 的 Ping 统计信息: 数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 0ms,最长 = 0ms,平均 = 0ms C:\Users\adamhuan>
可以看到,子网卡配置成功。
——————————————————
Done。