一、 目的
使用一台单网卡的Linux主机,使Switch上的两个以上的VLAN下的主机可以互访。适用于vlan间路由但又不想增加投资的应用。适用于所有支持VLAN的switch,本实验中使用的是H3C 3100。
二、 网络环境描述
PC-A,switch Port 8,ipadd=192.168.13.11,gw=192.168.13.254 PC-B,Switch Port 4,ipadd=192.168.12.22,gw=192.168.12.254 Linux的主机一台,Linux的eth0端口接在Switch Port 10。Linux发行版为CentOS 4.4,内核2.6.9-EL。Linux 2.6以上内核才支持802.1q,低版本则需要打补丁。
三、具体配置
1. H3C 3100配置 Port 1/0/4——vlan 3,接PC-A,
Port 1/0/8——vlan 2,接PC-B,
Port 1/0/10——vlan trunk,接Linux的eth0端口 # 将 port4 划分到vlan3 interface Ethernet1/0/4 port access vlan 3 # 将port 8划分到vlan 2 interface Ethernet1/0/8 port access vlan 2 # 将port 10划分为trunk,并允许所有vlan路由。如果有不需要路由的vlan,此处指定需要路由的具体的vlan id。 interface Ethernet1/0/10 port link-type trunk port trunk permit vlan all
2. CentOS 4.4配置 1) 加载802.1q的模块 modprobe 8021q
2) 清除eth0的ip地址 ip address add 0.0.0.0 dev eth0 3) 将eth0指定到vlan 2、3中 vconfig add eth0 2 vconfig add eth0 3 出现加入成功的提示:
1
[root@host ~]# vconfig add eth0 2
Added VLAN with VID == 2 to IF -:eth0:- 多次指定会出现错误提示
[root@host ~]# vconfig add eth0 2
ERROR: trying to add VLAN #2 to IF -:eth0:- error: Invalid argument 注意事项及排错需求
4) 为子接口设置IP地址 #vlan2的IP地址 ip address add 192.168.12.254 eth0.2 #vlan3的IP地址 ip address add 192.168.13.254 eth0.3 查看子接口的启动情况
注意,此处的eth0.2和eth0.3不同于eth0:2和eth0:3 5) 打开Linux的转发功能 echo 1 > /proc/sys/net/ipv4/ip_forward
或编辑/etc/sysctl.conf,将net.ipv4_forward的值修改为1,并执行sysctl –p。 6) 配置完成,PC-A和PC-B可以互访
2008-7-10
2
附1:划分子接口后的文件及配置变更
增加完毕后,在/proc/net/vlan目录下,新增两个配置文件 eth0.2、eth0.3 eth0.2的内容: eth0.2 VID: 2 REORDER_HDR: 1 dev->priv_flags: 21 total frames received 6609 total bytes received 1137771 Broadcast/Multicast Rcvd 2 total frames transmitted 4955 total bytes transmitted 411861 total headroom inc 0 total encap on xmit 4955 Device: eth0 INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 EGRESSS priority Mappings: Eth0.3的内容 eth0.3 VID: 3 REORDER_HDR: 1 dev->priv_flags: 21 total frames received 4452 total bytes received 283079 Broadcast/Multicast Rcvd 0 total frames transmitted 4847 total bytes transmitted 1092798 total headroom inc 0 total encap on xmit 4847 Device: eth0 INGRESS priority mappings: 0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0 EGRESSS priority Mappings: 7) /proc/net/vlan/config内容变更 VLAN Dev name | VLAN ID Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD eth0.2 | 2 | eth0 eth0.1 | 1 | eth0 #本次实验无用途 eth0.3 | 3 | eth0
3
附2:ifconfig查看配置 eth0 Link encap:Ethernet HWaddr 00:B0:D0:BC:80:3B inet6 addr: fe80::2b0:d0ff:febc:803b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:35505 errors:0 dropped:0 overruns:1 frame:0 TX packets:27085 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4168684 (3.9 MiB) TX bytes:21812960 (20.8 MiB) Interrupt:5 Base address:0xe480 eth0.2 Link encap:Ethernet HWaddr 00:B0:D0:BC:80:3B inet addr:192.168.12.254 Bcast:192.168.12.255 Mask:255.255.255.0 inet6 addr: fe80::2b0:d0ff:febc:803b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:5289 errors:0 dropped:0 overruns:0 frame:0 TX packets:3893 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1051999 (1.0 MiB) TX bytes:317237 (309.8 KiB) eth0.3 Link encap:Ethernet HWaddr 00:B0:D0:BC:80:3B inet addr:192.168.13.254 Bcast:192.168.13.255 Mask:255.255.255.0 inet6 addr: fe80::2b0:d0ff:febc:803b/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:3502 errors:0 dropped:0 overruns:0 frame:0 TX packets:3897 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:222306 (217.0 KiB) TX bytes:1019146 (995.2 KiB) 如果没有看到eth0.2和eth0.3,使用下面的命令启动子接口 ifconfig eth0.2 up ifconfig eth0.3 up
4
因篇幅问题不能全部显示,请点此查看更多更全内容