Linux與Window經路由器互相訪問
網絡拓撲圖:
實驗環境:Windows10(物理機)、VMware Workstation 12 Pro、Centos6(虛擬機)、Centos7(虛擬機)
主機A:Centos7.4
一塊僅主機模式網卡
IP:192.168.27.100/24
網關指向:192.168.27.200
主機B:windows10
IP:172.18.4.185/16
網關指向:172.18.0.200
Router0:Centos6.9模擬
網卡eth0(192.168.27.200/24),選擇僅主機模式
網卡eth1(10.0.0.200/8),選擇自定義VMnet2模式
Router1:centos6.9
網卡eth0(172.18.0.200/16),選擇橋接模式
網卡eth1(10.0.0.201/8),選擇自定義VMnet2模式
實驗流程:
A主機上操作
ifconfig ens33 192.168.27.100/24 指定IP
ifconfig 查看IP
route add default gw 192.168.27.200 指定網關
route -n 查看路由表
Router0上操作
ifconfig eth0 192.168.27.200/24 指定IP
ifconfig eth1 10.0.0.200/8 指定IP
chkconfig iptables off 關閉iptable
service iptables stop 停掉服務
iptables-vnL 查看沒啟用
setenforce 0 關閉SE策略
getenforce 查看
route add -net 172.18.0.0/16 gw 10.0.0.201 dev eth1 配置R1路由表(直連網段不需要添加,自動生成路由記錄)
route -n 查看路由記錄
echo 1 > /proc/sys/net/ipv4/ip_forward 開啟路由轉發功能
Router1上操作
ifconfig eth0 172.18.0.200/16 指定IP
ifconfig eth1 10.0.0.201/8 指定IP
chkconfig iptables off 關閉iptable
service iptables stop 停掉服務
iptables-vnL 查看沒啟用
setenforce 0 關閉SE策略
getenforce 查看
route add -net 192.168.27.0/24 gw 10.0.0.200 配置R2路由表(接口可以忽略不寫)
echo 1 > /proc/sys/net/ipv4/ip_forward 開啟路由轉發
A主機上操作
ping -I 192.168.27.100 172.18.4.185 可以ping通
Linux與Window經路由器互相訪問