描述:VirtualBox+GNS3创建虚拟机,模拟pc之间通信。
目标:让不在同一网段的PC2与PC3之间可以互相通信(俗称的ping通),这就需要通过路由PC1来跳转。
(1)设置IP地址如下;
PC1:192.168.1.1/24,eth0
192.168.2.1/24,eth1
PC2:192.168.1.2/24,eth0
PC3:192.168.2.2/24,eth1
命令及步骤如下:
PC1:sudo ip addressadd 192.168.1.1/24 dev eth0;
sudo ip address add 192.168.2.1/24 dev eth1;
启动网卡:sudo ip link set eth0 up;
sudo ip link set eth1 up;
PC2:sudo ip addressadd 192.168.1.2/24 dev eth0;
启动网卡:sudo ip link set eth0 up;
PC3:sudo ip addressadd 192.168.2.2/24 dev eth1;
启动网卡:sudo ip link set eth1 up;
(2)查看路由:route –n
添加默认路由:PC3 : sudo route add default gw192.168.2.1
PC2 : sudo route add default gw192.168.1.1
(3)PC1开启转发:
echo "1" > /proc/sys/net/ipv4/ip_forward
参考链接:https://blog.csdn.net/lemontree1945/article/details/80598242