网络:192.168.48.0 掩码:255.255.255.0 网关:192.168.48.1
查看网络
- ip addr
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
- inet 127.0.0.1/8 scope host lo
- valid_lft forever preferred_lft forever
-
- 2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
- inet 192.168.58.236/26 brd 195.201.58.255 scope global enp4s0
- valid_lft forever preferred_lft forever
复制代码
创建网桥
添加到 /etc/network/interfaces
其中 enp4s0 来自上一个命令的输出 2: enp4s0: <BROADCAST,MULTICAST
- auto vmbr1
- iface vmbr1 inet static
- address 192.168.48.1
- netmask 255.255.255.0
- bridge_ports none
- bridge_stp off
- bridge_fd 0
- post-up echo 1 > /proc/sys/net/ipv4/ip_forward
- post-up iptables -t nat -A POSTROUTING -s ‘192.168.48.0/24’ -o enp4s0 -j MASQUERADE
- post-down iptables -t nat -D POSTROUTING -s ‘192.168.48.0/24’ -o enp4s0 -j MASQUERADE
复制代码
启动网桥
- ifup vmr1
-
- Waiting for vmbr1 to get ready (MAXWAIT is 2 seconds).
-
- ip address show dev vmbr1
-
- 3: vmbr1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
- link/ether 16:cf:7e:23:de:1e brd ff:ff:ff:ff:ff:ff
- inet 192.168.48.1/24 brd 192.168.50.255 scope global vmbr1
- valid_lft forever preferred_lft forever
- inet6 fe80::14cf:7eff:fe23:de1e/64 scope link
- valid_lft forever preferred_lft forever
复制代码
重启网络服务
- systemctl restart networking
复制代码
|