Centos9使用nmcli创建隧道
原文:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/configuring-ip-tunnels_configuring-and-managing-networking
创建隧道, 模式ipip, 接口名tun0 , 附带参数可以加-- ip-tunnel.mtu 1500 ip-tunnel.ttl 255
nmcli connection add type ip-tunnel ip-tunnel.mode ipip con-name tun0 ifname tun0 remote 198.51.100.5 local 203.0.113.10
nmcli connection modify tun0 ipv4.addresses '10.0.1.1/30' #给tun0设置互联IP
nmcli connection modify tun0 ipv4.method manual #设置网口为手动
nmcli connection up tun0 #启用tun0隧道
B端设置一样,改变下互联IP.
nmcli connection modify tun0 +ipv4.routes "172.16.0.0/24 10.0.1.2" #可以添加ip路由表
查看网口
nmcli connection
删除隧道
nmcli conn del tun0
开启内核转发
echo "net.ipv4.ip_forward=1" >>/etc/sysctl.conf
sysctl -p
改成一键添加
addtun(){
nmcli connection add type ip-tunnel ip-tunnel.mode ipip con-name $1 ifname $1 remote $2 local $3 -- ip-tunnel.mtu 1500 ip-tunnel.ttl 255
nmcli connection modify $1 ipv4.addresses $4
nmcli connection modify $1 ipv4.method manual
nmcli connection up $1
}
addtun 网卡名 远程ip 本地IP 内网IP