When VXLAN was first implemented in Linux 3.7, the UDP port to use was not defined. Several vendors were using 8472 and Linux took the same value. To avoid breaking existing deployments, this is still the default value. Therefore, if you want to use the IANA-assigned port, you need to explicitely set it with dstport 4789.
2.1 点对点的 vxlan
分别在node0和node1创建点对点的vxlan设备(VTEP)
root@node0:~# ip link add vxlan0 type vxlan \
id 42 \
dstport 4789 \
remote 192.168.8.101 \
local 192.168.8.100 \
dev enp0s8
root@node0:~# ip addr add 10.20.1.2/24 dev vxlan0
root@node0:~# ip link set vxlan0 up
root@node1:~# ip link add vxlan0 type vxlan \
id 42 \
dstport 4789 \
remote 192.168.8.100 \
local 192.168.8.101 \
dev enp0s8
root@node1:~# ip addr add 10.20.1.3/24 dev vxlan0
root@node1:~# ip link set vxlan0 up
现在我们可以在node0上ping 10.20.1.3这个ip了:
root@node0:~# ping 10.20.1.3
PING 10.20.1.3 (10.20.1.3) 56(84) bytes of data.
64 bytes from 10.20.1.3: icmp_seq=1 ttl=64 time=0.675 ms
64 bytes from 10.20.1.3: icmp_seq=2 ttl=64 time=0.719 ms
同时,我们可以通过tcpdump -i enp0s8查看vxlan包:
root@node0:~# tcpdump -i enp0s8
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s8, link-type EN10MB (Ethernet), capture size 262144 bytes
15:04:03.200902 IP 172.28.128.3.51042 > 172.28.128.4.4789: VXLAN, flags [I] (0x08), vni 42
ARP, Request who-has 10.20.1.3 tell 10.20.1.2, length 28
15:04:03.201379 IP 172.28.128.4.43593 > 172.28.128.3.4789: VXLAN, flags [I] (0x08), vni 42
ARP, Reply 10.20.1.3 is-at c6:3d:f6:4d:16:2d (oui Unknown), length 28
15:04:03.201503 IP 172.28.128.3.53381 > 172.28.128.4.4789: VXLAN, flags [I] (0x08), vni 42
IP 10.20.1.2 > 10.20.1.3: ICMP echo request, id 2098, seq 1, length 64
tcpdump -l -n -i <if> 'port 4789 and udp[8:2] = 0x0800 & 0x0800 and udp[11:4] = <vni> & 0x00FFFFFF'
2.2 多播模式的 vxlan
分别在node0、node1、node2创建多播的vxlan设备(VTEP)
root@node0:~# ip link add vxlan0 type vxlan \
id 42 \
dstport 4789 \
group 239.1.1.1 \
dev enp0s8
root@node0:~# ip addr add 10.20.1.2/24 dev vxlan0
root@node0:~# ip link set vxlan0 up
# node0
root@node0:~# /vagrant/config_docker0.sh 192.168.0.1/24
root@node0:~# ip link add vxlan0 type vxlan \
id 42 \
dstport 4789 \
group 239.1.1.1 \
dev enp0s8
root@node0:~# ip link set vxlan0 master docker0
root@node0:~# ip link set vxlan0 up