赞
踩
[root@computer1 ~]# ip netns add dhcp01
[root@network1 ~]# ovs-vsctl add-port br-int tapdhcp01 -- set interface tapdhcp01 type=internal
[root@network1 ~]# ovs-vsctl set port tapdhcp01 tag=100
[root@network1 ~]# ip link set tapdhcp01 netns dhcp01
[root@network1 ~]# ip netns exec dhcp01 ip addr add 192.168.1.2/24 dev tapdhcp01[root@network1 ~]# ip netns exec dhcp01 ip link set tapdhcp01 up
[root@network1 ~]# ip netns exec dhcp01 ping 192.168.1.12
PING 192.168.1.12 (192.168.1.12) 56(84) bytes of data.
64 bytes from 192.168.1.12: icmp_seq=1 ttl=64 time=5.30 ms
64 bytes from 192.168.1.12: icmp_seq=2 ttl=64 time=0.629 ms
^C
--- 192.168.1.12 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1891ms
rtt min/avg/max/mdev = 0.629/2.965/5.302/2.337 ms
[root@network1 ~]# ip netns exec dhcp01 ping 192.168.1.11
PING 192.168.1.11 (192.168.1.11) 56(84) bytes of data.
64 bytes from 192.168.1.11: icmp_seq=1 ttl=64 time=2.61 ms
64 bytes from 192.168.1.11: icmp_seq=2 ttl=64 time=0.237 ms
64 bytes from 192.168.1.11: icmp_seq=3 ttl=64 time=0.205 ms
^C
--- 192.168.1.11 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2234ms
rtt min/avg/max/mdev = 0.205/1.018/2.612/1.127 ms
5

[root@network1 ~]# ovs-vsctl add-br br-ex
vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
PROMISC=yes
MTU=1546
vi /etc/sysconfig/network-scripts/ifcfg-br-ex
DEVICE=br-ex
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=none
IPADDR0=172.16.0.201
PREFIX0=24
[root@network1 ~]# ovs-vsctl add-port br-ex eth1 && service network restart
Shutting down interface br-ex: [ OK ]
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down interface eth3: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Determining if ip address 10.20.0.201 is already in use for device eth0...
[ OK ]
Bringing up interface eth1: RTNETLINK answers: Invalid argument
[ OK ]
Bringing up interface eth2: Determining if ip address 192.168.4.201 is already in use for device eth2...
[ OK ]
Bringing up interface eth3:
Determining IP information for eth3... done.
[ OK ]
Bringing up interface br-ex: device br-ex already exists; can't create bridge with the same name
[FAILED]

[root@network1 ~]# ip addr add 172.16.0.201/24 dev br-ex
[root@network1 ~]# ping 172.16.0.201
PING 172.16.0.201 (172.16.0.201) 56(84) bytes of data.
64 bytes from 172.16.0.201: icmp_seq=1 ttl=64 time=0.019 ms
64 bytes from 172.16.0.201: icmp_seq=2 ttl=64 time=0.030 ms
^C
--- 172.16.0.201 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1841ms
rtt min/avg/max/mdev = 0.019/0.024/0.030/0.007 ms
[root@network1 ~]# ip netns add router01
[root@network1 ~]# ovs-vsctl add-port br-int qr01 -- set interface qr01 type=internal
ip link set lo up[root@network1 ~]# ovs-vsctl set port qr01 tag=100
[root@network1 ~]#
[root@network1 ~]# ip link set qr01 netns router01
[root@network1 ~]# ip netns exec router01 ip addr add 192.168.1.1/24 dev qr01
[root@network1 ~]# ip netns exec router01 ip link set qr01 up
[root@network1 ~]# ip netns exec router01 ip link set lo up
[root@network1 ~]# ovs-vsctl add-port br-ex qg01 -- set interface qg01 type=internal
[root@network1 ~]# ip link set qg01 netns router01
[root@network1 ~]# ip netns exec router01 ip addr add 172.16.0.100/24 dev qg01
[root@network1 ~]# ip netns exec router01 ip link set qg01 up
[root@network1 ~]# ip netns exec router01 ip link set lo up
[root@network1 ~]# ip netns exec router01 ping 192.168.1.11
PING 192.168.1.11 (192.168.1.11) 56(84) bytes of data.
64 bytes from 192.168.1.11: icmp_seq=1 ttl=64 time=3.20 ms
64 bytes from 192.168.1.11: icmp_seq=2 ttl=64 time=0.280 ms
64 bytes from 192.168.1.11: icmp_seq=3 ttl=64 time=0.393 ms
^C
--- 192.168.1.11 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2026ms
rtt min/avg/max/mdev = 0.280/1.292/3.204/1.352 ms
[root@network1 ~]# ip netns exec router01 ping 192.168.1.12
PING 192.168.1.12 (192.168.1.12) 56(84) bytes of data.
64 bytes from 192.168.1.12: icmp_seq=1 ttl=64 time=1.36 ms
64 bytes from 192.168.1.12: icmp_seq=2 ttl=64 time=0.245 ms
^C
--- 192.168.1.12 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1894ms
rtt min/avg/max/mdev = 0.245/0.803/1.361/0.558 ms
[root@network1 ~]# ip netns exec router01 ping 172.16.0.202
PING 172.16.0.202 (172.16.0.202) 56(84) bytes of data.
64 bytes from 172.16.0.202: icmp_seq=1 ttl=64 time=2.40 ms
64 bytes from 172.16.0.202: icmp_seq=2 ttl=64 time=0.253 ms
64 bytes from 172.16.0.202: icmp_seq=3 ttl=64 time=0.612 ms
^C
--- 172.16.0.202 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2135ms
rtt min/avg/max/mdev = 0.253/1.088/2.400/0.939 ms

[root@network1 ~]# ping 172.16.0.100
PING 172.16.0.100 (172.16.0.100) 56(84) bytes of data.
64 bytes from 172.16.0.100: icmp_seq=1 ttl=63 time=3.00 ms
64 bytes from 172.16.0.100: icmp_seq=2 ttl=63 time=0.834 ms
^C
--- 172.16.0.100 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1927ms
rtt min/avg/max/mdev = 0.834/1.917/3.000/1.083 ms
[root@network1 ~]# ip netns exec router01 ip addr add 172.16.0.101/32 dev qg01
[root@network1 ~]# ip netns exec router01 iptables -t nat -A OUTPUT -d 172.16.0.101/32 -j DNAT --to-destination 192.168.1.11
at -A POSTROUTING -s 192.168.1.11/32 -j SNAT --to-source 172.16.0.101
ip netns exec router01 iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 172.16.0.100[root@network92.168.1.11tns exec router01 iptables -t nat -A PREROUTING -d 172.16.0.101/32 -j DNAT --to-destination 1
[root@network1 ~]# ip netns exec router01 iptables -t nat -A POSTROUTING -s 192.168.1.11/32 -j SNAT --to-source 172.16.0.101
[root@network1 ~]# ip netns exec router01 iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 172.16.0.100
[root@network1 ~]# ip netns exec router01 iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT all -- anywhere 172.16.0.101 to:192.168.1.11
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
SNAT all -- 192.168.1.11 anywhere to:172.16.0.101
SNAT all -- 192.168.1.0/24 anywhere to:172.16.0.100
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
DNAT all -- anywhere 172.16.0.101 to:192.168.1.11
- [root@network1 ~]# ping 172.16.0.101
- PING 172.16.0.101 (172.16.0.101) 56(84) bytes of data.
- 64 bytes from 172.16.0.101: icmp_seq=1 ttl=62 time=2.12 ms
- 64 bytes from 172.16.0.101: icmp_seq=2 ttl=62 time=2.69 ms
- 64 bytes from 172.16.0.101: icmp_seq=3 ttl=62 time=1.13 ms
- 64 bytes from 172.16.0.101: icmp_seq=4 ttl=62 time=0.740 ms
- 64 bytes from 172.16.0.101: icmp_seq=5 ttl=62 time=1.45 ms
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。