/etc/network/interfacesの設定メモ

知り合いとのやりとりメモ。

設定

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
##iface eth0 inet dhcp
iface eth0 inet static
address 192.168.0.9
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.30
up /sbin/route add -net 192.168.22.0 netmask 255.255.255.0 gw 192.168.0.50 dev eth0
up /sbin/route add -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.0.49 dev eth0
up /sbin/route add -net 192.168.50.0 netmask 255.255.255.0 gw 192.168.0.51 dev eth0
up /sbin/route add -net 192.168.51.0 netmask 255.255.255.0 gw 192.168.0.52 dev eth0
down /sbin/route del -net 192.168.22.0 netmask 255.255.255.0 gw 192.168.0.50 dev eth0
down /sbin/route del -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.0.49 dev eth0
down /sbin/route del -net 192.168.50.0 netmask 255.255.255.0 gw 192.168.0.51 dev eth0
down /sbin/route del -net 192.168.51.0 netmask 255.255.255.0 gw 192.168.0.52 dev eth0

実行結果

$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.22.0    192.168.0.50    255.255.255.0   UG        0 0          0 eth0
192.168.20.0    192.168.0.49    255.255.255.0   UG        0 0          0 eth0
192.168.50.0    192.168.0.51    255.255.255.0   UG        0 0          0 eth0
192.168.51.0    192.168.0.52    255.255.255.0   UG        0 0          0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         192.168.0.30    0.0.0.0         UG        0 0          0 eth0