這篇文章將為大家詳細(xì)講解有關(guān)ubuntu中VETH虛擬接口的示例分析,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
恩平網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,恩平網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為恩平1000多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的恩平做網(wǎng)站的公司定做!
virtual ethernet pair (VETH pair)
Veth是Linux中一種虛擬出來的網(wǎng)絡(luò)設(shè)備,veth設(shè)備總是成對(duì)出現(xiàn),所以一般也叫veth-pair。數(shù)據(jù)會(huì)從一頭進(jìn)入另一頭出去,所以類似于網(wǎng)線的作用。
用途:
由于veth的“網(wǎng)線”特性,它常常充當(dāng)著一個(gè)橋梁,連接著各種虛擬網(wǎng)絡(luò)設(shè)備。常見用途是連接兩個(gè)netwok namespace,或者連接Linux-Bridge、OVS 之類的(現(xiàn)在市面上的容器多是使用veth連接的,另外還有tun/tap接口多用于虛擬機(jī),他倆的區(qū)別,veth:相當(dāng)于兩頭是水晶頭的一根網(wǎng)段;tun/tap:相當(dāng)于一頭是水晶頭,一頭是usb -_-)
Ubuntu18.04
ip link add tap1 type veth peer name tap2 ip netns add red ip netns add blue ip link set tap1 netns red ip link set tap2 netns blue ip netns exec red ip a ip netns exec red ip link set tap1 up ip netns exec red ifconfig tap1 192.168.1.2/24 ip netns exec blue ip a ip netns exec blue ip link set tap2 up ip netns exec blue ifconfig tap2 192.168.1.3/24 ip netns exec red ping 192.168.1.3 ip netns exec blue ping 192.168.1.2 # 刪除一端,另一端會(huì)自動(dòng)刪除 ip link del tap1 # 刪除ns,會(huì)連帶veth一起刪除 ip nets del red
創(chuàng)建veth接口,可見多了tap1和tap2接口
root@ubuntu:~# ip link add tap1 type veth peer name tap2 root@ubuntu:~# ip a 1: lo:mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc mq state DOWN group default qlen 1000 link/ether 00:50:56:ab:c5:2a brd ff:ff:ff:ff:ff:ff 3: tap2@tap1: mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 8e:0b:86:3f:f4:79 brd ff:ff:ff:ff:ff:ff 4: tap1@tap2: mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 86:bd:8e:03:29:68 brd ff:ff:ff:ff:ff:ff
創(chuàng)建命名空間
root@ubuntu:~# ip netns add red root@ubuntu:~# ip netns add blue root@ubuntu:~# ip netns blue red
接口接入命名空間,再ip a查看,已經(jīng)看不到tap1和tap2,因?yàn)槿サ礁髯缘拿臻g去了
root@ubuntu:~# ip link set tap1 netns red root@ubuntu:~# ip link set tap2 netns blue root@ubuntu:~# ip a 1: lo:mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: mtu 1500 qdisc mq state DOWN group default qlen 1000 link/ether 00:50:56:ab:c5:2a brd ff:ff:ff:ff:ff:ff root@ubuntu:~#
在各命名空間里啟動(dòng)接口,設(shè)置IP
tap1
root@ubuntu:~# ip netns exec red ip a 1: lo:mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 6: tap1@if5: mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 86:bd:8e:03:29:68 brd ff:ff:ff:ff:ff:ff link-netnsid 1 root@ubuntu:~# ip netns exec red ip link set tap1 up root@ubuntu:~# ip netns exec red ifconfig tap1 192.168.1.2/24 root@ubuntu:~# ip netns exec red ip a 1: lo: mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 6: tap1@if5: mtu 1500 qdisc noqueue state LOWERLAYERDOWN group default qlen 1000 link/ether 86:bd:8e:03:29:68 brd ff:ff:ff:ff:ff:ff link-netnsid 1 inet 192.168.1.2/24 brd 192.168.1.255 scope global tap1 valid_lft forever preferred_lft forever
tap2
root@ubuntu:~# ip netns exec blue ip a 1: lo:mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 5: tap2@if6: mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 8e:0b:86:3f:f4:79 brd ff:ff:ff:ff:ff:ff link-netnsid 0 root@ubuntu:~# ip netns exec blue ip link set tap2 up root@ubuntu:~# ip netns exec blue ifconfig tap2 192.168.1.3/24 root@ubuntu:~# ip netns exec blue ip a 1: lo: mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 5: tap2@if6: mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 8e:0b:86:3f:f4:79 brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 192.168.1.3/24 brd 192.168.1.255 scope global tap2 valid_lft forever preferred_lft forever inet6 fe80::8c0b:86ff:fe3f:f479/64 scope link valid_lft forever preferred_lft forever
ping測(cè)試
root@ubuntu:~# ip netns exec red ping 192.168.1.3 PING 192.168.1.3 (192.168.1.3) 56(84) bytes of data. 64 bytes from 192.168.1.3: icmp_seq=1 ttl=64 time=0.047 ms 64 bytes from 192.168.1.3: icmp_seq=2 ttl=64 time=0.035 ms ^C --- 192.168.1.3 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1006ms rtt min/avg/max/mdev = 0.035/0.041/0.047/0.006 ms root@ubuntu:~# root@ubuntu:~# root@ubuntu:~# ip netns exec blue ping 192.168.1.2 PING 192.168.1.2 (192.168.1.2) 56(84) bytes of data. 64 bytes from 192.168.1.2: icmp_seq=1 ttl=64 time=0.021 ms 64 bytes from 192.168.1.2: icmp_seq=2 ttl=64 time=0.037 ms 64 bytes from 192.168.1.2: icmp_seq=3 ttl=64 time=0.031 ms ^C --- 192.168.1.2 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2050ms rtt min/avg/max/mdev = 0.021/0.029/0.037/0.009 ms
關(guān)于“ubuntu中VETH虛擬接口的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。