如题:
做转发的电脑操作:
临时生效: echo “1” > /proc/sys/net/ipv4/ip_forward
永久生效:
修改sysctl.conf: net.ipv4.ip_forward = 1
再执行sysctl -p立即生效
做转发的电脑ip:
外网口:inet 10.20.4.63 netmask 255.255.254.0 broadcast 10.20.5.255
转发口: inet 10.20.4.64 netmask 255.255.254.0 broadcast 10.20.5.255
做转发的电脑路由:
Destination | Gateway | Genmask | Flags | Metric | Ref | Use | Iface |
---|---|---|---|---|---|---|---|
0.0.0.0 | 10.20.5.254 | 0.0.0.0 | UG | 100 | 0 | 0 | enp0s3f0 |
10.20.4.65 | 0.0.0.0 | 255.255.255.255 | UH | 0 | 0 | 0 | enp0s3f1 |
另一台的电脑ip:
inet 10.20.4.65 netmask 255.255.254.0 broadcast 10.20.5.255
另一台的电脑路由:
Destination | Gateway | Genmask | Flags | Metric | Ref | Use | Iface |
---|---|---|---|---|---|---|---|
0.0.0.0 | 10.20.4.64 | 0.0.0.0 | UG | 100 | 0 | 0 | enp3s0 |
10.20.4.64 | 0.0.0.0 | 255.255.255.255 | UH | 0 | 0 | 0 | enp3s0 |
PS:
路由操作
route add -net 10.20.4.64 netmask 255.255.255.255 dev enp3s0
ip操作:
ifconfig enp0s3f1 10.20.4.64 netmask 255.255.254.0
参考资料:
- https://blog.csdn.net/m0_52158631/article/details/110006645
- https://www.linuxprobe.com/ubuntu-conn-town.html