別のサブネットへ到達するには

192.168.1.0,192.168.2.0の2つのネットワークが有り、192.168.1.3に更にルータが接続されこれをゲートウェイにしてネットワーク:192.168.3.0が繋がっている。
自分は以下のように接続されている。

$ ifconfig
eth0 Link encap:Ethernet HWaddr 10:bf:48:ba:ae:f2
inet addr:192.168.2.99 Bcast:192.168.2.255 Mask:255.255.255.0
gateway:192.168.2.1 DHCP:192.168.2.1 DNS:192.168.2.1

eth1 Link encap:Ethernet HWaddr ec:88:8f:eb:b1:9c
inet addr:192.168.3.99 Bcast:192.168.3.255 Mask:255.255.255.0

$ route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
192.168.2.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.168.3.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1

$ ping 192.168.1.59
PING 192.168.1.59 (192.168.1.59) 56(84) bytes of data.
From 192.168.1.59 icmp_seq=1 Destination Host Unreachable
From 192.168.1.59 icmp_seq=2 Destination Host Unreachable

この状態でネットワーク:192.168.1.0下のデバイス:192.168.1.59にアクセスするには


sudo route add -net 192.168.1.0 gw 192.168.3.1 netmask 255.255.255.0 dev eth1


$ route -n
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
192.168.1.0 192.168.3.1 255.255.255.0 UG 0 0 0 eth1
192.168.2.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.168.3.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1

$ ping 192.168.1.59
PING 192.168.1.59 (192.168.1.59) 56(84) bytes of data.
64 bytes from 192.168.1.59: icmp_req=1 ttl=63 time=0.729 ms
64 bytes from 192.168.1.59: icmp_req=2 ttl=63 time=0.537 ms