IPIP
IPIP
隧道是一种点对点的隧道协议,用于在IPv4网络上传输IPv4或IPv6数据包。IPIP
隧道的工作原理是将源主机的IP数据包封装在一个新的IP数据包中,新的IP数据包的目的地址是隧道的另一端。在隧道的另一端,接收方将解封装原始IP数据包,并将其传递到目标主机。IPIP
隧道可以在不同的网络之间建立连接,例如在IPv4网络和IPv6网络之间建立连接。
一、使用 Containerlab
模拟网络
a | 拓扑
b | 网络拓扑文件
# ipip.clab.yml
name: ipip
topology:
nodes:
gw1:
kind: linux
image: vyos/vyos:1.2.8
cmd: /sbin/init
binds:
- /lib/modules:/lib/modules
- ./startup-conf/gw1.cfg:/opt/vyatta/etc/config/config.boot
gw2:
kind: linux
image: vyos/vyos:1.2.8
cmd: /sbin/init
binds:
- /lib/modules:/lib/modules
- ./startup-conf/gw2.cfg:/opt/vyatta/etc/config/config.boot
server1:
kind: linux
image: harbor.dayuan1997.com/devops/nettool:0.9
exec:
- ip addr add 10.1.5.10/24 dev net0
- ip route replace default via 10.1.5.1
server2:
kind: linux
image: harbor.dayuan1997.com/devops/nettool:0.9
exec:
- ip addr add 10.1.8.10/24 dev net0
- ip route replace default via 10.1.8.1
links:
- endpoints: ["gw1:eth1", "server1:net0"]
- endpoints: ["gw2:eth1", "server2:net0"]
- endpoints: ["gw1:eth2", "gw2:eth2"]
c | VyOS
配置文件
gw1.cfg
配置文件
# ./startup-conf/gw1.cfg
interfaces {
ethernet eth1 {
address 10.1.5.1/24
duplex auto
smp-affinity auto
speed auto
}
ethernet eth2 {
address 172.12.1.10/24
duplex auto
smp-affinity auto
speed auto
}
loopback lo {
}
tunnel tun0 {
# 配置 ipip 设置本端地址,远端地址
address 1.1.1.1/24
encapsulation ipip
local-ip 172.12.1.10
multicast disable
remote-ip 172.12.1.11
}
}
protocols {
static {
# 静态路由,指定到达 10.1.8.0/24 网络的下一条为 1.1.1.2, 1.1.1.2 和 1.1.1.1 组成了 ipip
route 10.1.8.0/24 {
next-hop 1.1.1.2 {
}
}
}
}
system {
config-management {
commit-revisions 100
}
console {
device ttyS0 {
speed 9600
}
}
host-name vyos
login {
user vyos {
authentication {
encrypted-password $6$QxPS.uk6mfo$9QBSo8u1FkH16gMyAVhus6fU3LOzvLR9Z9.82m3tiHFAxTtIkhaZSWssSgzt4v4dGAL8rhVQxTg0oAG9/q11h/
plaintext-password ""
}
level admin
}
}
ntp {
server 0.pool.ntp.org {
}
server 1.pool.ntp.org {
}
server 2.pool.ntp.org {
}
}
syslog {
global {
facility all {
level info
}
facility protocols {
level debug
}
}
}
time-zone UTC
}
/* Warning: Do not remove the following line. */
/* === vyatta-config-version: "dns-forwarding@1:mdns@1:ssh@1:webproxy@1:webgui@1:zone-policy@1:broadcast-relay@1:l2tp@1:cluster@1:snmp@1:pppoe-server@2:conntrack@1:wanloadbalance@3:webproxy@2:firewall@5:ntp@1:dhcp-server@5:dhcp-relay@2:system@10:nat@4:quagga@7:qos@1:ipsec@5:conntrack-sync@1:config-management@1:vrrp@2:pptp@1" === */
/* Release version: 1.2.8 */
gw2.cfg
配置文件
# ./startup-conf/gw2.cfg
interfaces {
ethernet eth1 {
address 10.1.8.1/24
duplex auto
smp-affinity auto
speed auto
}
ethernet eth2 {
address 172.12.1.11/24
duplex auto
smp-affinity auto
speed auto
}
loopback lo {
}
tunnel tun0 {
# 配置 ipip 设置本端地址,远端地址
address 1.1.1.2/24
encapsulation ipip
local-ip 172.12.1.11
multicast disable
remote-ip 172.12.1.10
}
}
protocols {
static {
# 静态路由,指定到达 10.1.8.0/24 网络的下一条为 1.1.1.1, 1.1.1.1 和 1.1.1.2 组成了 ipip
route 10.1.5.0/24 {
next-hop 1.1.1.1 {
}
}
}
}
system {
config-management {
commit-revisions 100
}
console {
device ttyS0 {
speed 9600
}
}
host-name vyos
login {
user vyos {
authentication {
encrypted-password $6$QxPS.uk6mfo$9QBSo8u1FkH16gMyAVhus6fU3LOzvLR9Z9.82m3tiHFAxTtIkhaZSWssSgzt4v4dGAL8rhVQxTg0oAG9/q11h/
plaintext-password ""
}
level admin
}
}
ntp {
server 0.pool.ntp.org {
}
server 1.pool.ntp.org {
}
server 2.pool.ntp.org {
}
}
syslog {
global {
facility all {
level info
}
facility protocols {
level debug
}
}
}
time-zone UTC
}
/* Warning: Do not remove the following line. */
/* === vyatta-config-version: "dns-forwarding@1:mdns@1:ssh@1:webproxy@1:webgui@1:zone-policy@1:broadcast-relay@1:l2tp@1:cluster@1:snmp@1:pppoe-server@2:conntrack@1:wanloadbalance@3:webproxy@2:firewall@5:ntp@1:dhcp-server@5:dhcp-relay@2:system@10:nat@4:quagga@7:qos@1:ipsec@5:conntrack-sync@1:config-management@1:vrrp@2:pptp@1" === */
/* Release version: 1.2.8 */
d | 部署服务
# tree -L 2 ./
./
├── ipip.clab.yml
└── startup-conf
├── gw1.cfg
└── gw2.cfg
# clab deploy -t ipip.clab.yml
INFO[0000] Containerlab v0.54.2 started
INFO[0000] Parsing & checking topology file: clab.yaml
INFO[0000] Creating docker network: Name="clab", IPv4Subnet="172.20.20.0/24", IPv6Subnet="2001:172:20:20::/64", MTU=1500
INFO[0000] Creating lab directory: /root/wcni-kind/network/5-demo-cni/7-ipip/1-clab-ipip/clab-ipip
INFO[0000] Creating container: "gw2"
INFO[0000] Creating container: "server1"
INFO[0000] Creating container: "server2"
INFO[0000] Creating container: "gw1"
INFO[0001] Created link: gw2:eth1 <--> server2:net0
INFO[0001] Created link: gw1:eth1 <--> server1:net0
INFO[0001] Created link: gw1:eth2 <--> gw2:eth2
INFO[0001] Executed command "ip addr add 10.1.5.10/24 dev net0" on the node "server1". stdout:
INFO[0001] Executed command "ip route replace default via 10.1.5.1" on the node "server1". stdout:
INFO[0001] Executed command "ip addr add 10.1.8.10/24 dev net0" on the node "server2". stdout:
INFO[0001] Executed command "ip route replace default via 10.1.8.1" on the node "server2". stdout:
INFO[0001] Adding containerlab host entries to /etc/hosts file
INFO[0001] Adding ssh config for containerlab nodes
INFO[0001]
标签:10.1,24,set,ip,IPIP,dev,虚拟,Linux,ipip
From: https://www.cnblogs.com/evescn/p/18254864