虚拟化部署之linux网卡的VLAN配置(2)
时间:2015-04-29 15:22 来源:linux.it.net.cn 作者:IT
三、在Linux配置VLAN Trunk:
由于在Linux上eth1要被设定为Trunk,并且属于特定的3111VLAN。eth2也要被设定为Trunk,并且属于特定的3112VLAN。
1.将eth1添加到VLAN 3111中:
[root@test]# vconfig add eth1 3111
WARNING: Could not open/proc/net/vlan/config. Maybe you need to load the 8021q module, or maybe youare not using PROCFS??
Added VLAN with VID == 3111 to IF -:eth1:-
第一次添加VLAN虚拟网卡的时候就一定会出现上面的那句提示,原因是因为默认下/proc/net/vlan/config这个专门用来保存VLAN信息的文件是没有的。由于第一次添加VLAN网卡,那么这个文件也会被自动建立起来。另外,在/proc/目录下面的文件都是系统的临时文件,因此重新启动后必定丢失休息,所以在配置并测试VLAN成功后,可以将一些相关命令添加到rc.local这个启动脚本当中去。在执行该命令之前可以先到/proc/net/目录查看下,并不存在vlan文件夹,执行后会创建一个vlan文件夹,并生成config配置文件,以及对应的虚拟vlan网卡配置文件 eth1.3111等.
2.同样将eth2添加到VLAN3112中:
[root@test ~]# vconfig add eth2 3112
Added VLAN with VID == 3112 to IF -:eth2:-
3.检查添加的VLAN虚拟网卡信息:
[root@test ~]# cat/proc/net/vlan/config
--------------------------------------------------
VLAN Dev name | VLAN ID
Name-Type:VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
eth1.3111 | 3111 | eth1
eth2.3112 | 3112 | eth2
可以看到所有的VLAN虚拟网卡以及它们所归属的主物理网卡。
(如果只有一个物理网卡,也可配置为文件ifcfg-eth1.3111和ifcfg-eth1.3112)
4.为VLAN虚拟网卡设定IP地址并且进行启用:
[root@test ~]# ifconfig eth1.3111 192.168.20.1 up
[root@test ~]# ifconfig eth2.3112 192.168.30.1 up
这是临时的,可以这样做
利用cp命令复制接口的ip地址配置
cp ifcfg-eth1 ifcfg-eth1.3111
cp ifcfg-eth2 ifcfg-eth2.3112
把ifcfg-eth1和ifcfg-eth2中的原有地址去掉,再vi修改ifcfg-eth1.3111和ifcfg-eth2.3112文件,设置IP地址等信息。
5.最后重启network服务,令配置生效。
重新启动网络服务
[root@test ~]# service network restart
--------------------------------------------------
Shutting down interface eth1: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth1: [ OK ]
Bringing up interface eth2: [ OK ]
--------------------------------------------------
6.检查Linux系统下的所有网络接口信息:
[root@test ~]# ifconfig |more
到这里已经基本上将VLAN的主要配置完成了。
7、验证连通性
[root@test ~]# ping 192.168.20.254
PING 192.168.20.254 (192.168.20.254) 56(84) bytes of data.
64 bytes from 192.168.20.254: icmp_seq=1 ttl=255 time=8.42 ms
64 bytes from 192.168.20.254: icmp_seq=2 ttl=255 time=1.47 ms
64 bytes from 192.168.20.254: icmp_seq=3 ttl=255 time=1.51 ms
64 bytes from 192.168.20.254: icmp_seq=4 ttl=255 time=1.58 ms
^C
--- 192.168.20.254 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 6325ms
rtt min/avg/max/mdev = 1.470/2.550/8.427/2.400 ms
[root@test ~]# ping 192.168.30.254
PING 192.168.30.254 (192.168.30.254) 56(84) bytes of data.
64 bytes from 192.168.30.254: icmp_seq=1 ttl=255 time=8.42 ms
64 bytes from 192.168.30.254: icmp_seq=2 ttl=255 time=1.47 ms
64 bytes from 192.168.30.254: icmp_seq=3 ttl=255 time=1.51 ms
64 bytes from 192.168.30.254: icmp_seq=4 ttl=255 time=1.58 ms
^C
--- 192.168.30.254 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 6325ms
rtt min/avg/max/mdev = 1.470/2.550/8.427/2.400 ms
(责任编辑:IT)
三、在Linux配置VLAN Trunk: 由于在Linux上eth1要被设定为Trunk,并且属于特定的3111VLAN。eth2也要被设定为Trunk,并且属于特定的3112VLAN。 1.将eth1添加到VLAN 3111中: [root@test]# vconfig add eth1 3111 WARNING: Could not open/proc/net/vlan/config. Maybe you need to load the 8021q module, or maybe youare not using PROCFS?? Added VLAN with VID == 3111 to IF -:eth1:- 第一次添加VLAN虚拟网卡的时候就一定会出现上面的那句提示,原因是因为默认下/proc/net/vlan/config这个专门用来保存VLAN信息的文件是没有的。由于第一次添加VLAN网卡,那么这个文件也会被自动建立起来。另外,在/proc/目录下面的文件都是系统的临时文件,因此重新启动后必定丢失休息,所以在配置并测试VLAN成功后,可以将一些相关命令添加到rc.local这个启动脚本当中去。在执行该命令之前可以先到/proc/net/目录查看下,并不存在vlan文件夹,执行后会创建一个vlan文件夹,并生成config配置文件,以及对应的虚拟vlan网卡配置文件 eth1.3111等. 2.同样将eth2添加到VLAN3112中: [root@test ~]# vconfig add eth2 3112 Added VLAN with VID == 3112 to IF -:eth2:- 3.检查添加的VLAN虚拟网卡信息: [root@test ~]# cat/proc/net/vlan/config -------------------------------------------------- VLAN Dev name | VLAN ID Name-Type:VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD eth1.3111 | 3111 | eth1 eth2.3112 | 3112 | eth2 可以看到所有的VLAN虚拟网卡以及它们所归属的主物理网卡。 (如果只有一个物理网卡,也可配置为文件ifcfg-eth1.3111和ifcfg-eth1.3112) 4.为VLAN虚拟网卡设定IP地址并且进行启用: [root@test ~]# ifconfig eth1.3111 192.168.20.1 up [root@test ~]# ifconfig eth2.3112 192.168.30.1 up 这是临时的,可以这样做 利用cp命令复制接口的ip地址配置 cp ifcfg-eth1 ifcfg-eth1.3111 cp ifcfg-eth2 ifcfg-eth2.3112 把ifcfg-eth1和ifcfg-eth2中的原有地址去掉,再vi修改ifcfg-eth1.3111和ifcfg-eth2.3112文件,设置IP地址等信息。 5.最后重启network服务,令配置生效。 重新启动网络服务 [root@test ~]# service network restart -------------------------------------------------- Shutting down interface eth1: [ OK ] Shutting down interface eth2: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth1: [ OK ] Bringing up interface eth2: [ OK ] -------------------------------------------------- 6.检查Linux系统下的所有网络接口信息: [root@test ~]# ifconfig |more 到这里已经基本上将VLAN的主要配置完成了。 7、验证连通性 [root@test ~]# ping 192.168.20.254 PING 192.168.20.254 (192.168.20.254) 56(84) bytes of data. 64 bytes from 192.168.20.254: icmp_seq=1 ttl=255 time=8.42 ms 64 bytes from 192.168.20.254: icmp_seq=2 ttl=255 time=1.47 ms 64 bytes from 192.168.20.254: icmp_seq=3 ttl=255 time=1.51 ms 64 bytes from 192.168.20.254: icmp_seq=4 ttl=255 time=1.58 ms ^C --- 192.168.20.254 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 6325ms rtt min/avg/max/mdev = 1.470/2.550/8.427/2.400 ms [root@test ~]# ping 192.168.30.254 PING 192.168.30.254 (192.168.30.254) 56(84) bytes of data. 64 bytes from 192.168.30.254: icmp_seq=1 ttl=255 time=8.42 ms 64 bytes from 192.168.30.254: icmp_seq=2 ttl=255 time=1.47 ms 64 bytes from 192.168.30.254: icmp_seq=3 ttl=255 time=1.51 ms 64 bytes from 192.168.30.254: icmp_seq=4 ttl=255 time=1.58 ms ^C --- 192.168.30.254 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 6325ms rtt min/avg/max/mdev = 1.470/2.550/8.427/2.400 ms (责任编辑:IT) |