[[PageOutline]] = default gateway = * default gateway (default route)の変更方法・扱い = 複数設定されているとき = == CentOS == === ifcfg-eth? === * ifcfg-eth? に書いた場合 * /etc/sysconfig/network-scripts/ifcfg-eth0 {{{ DEVICE=eth0 BOOTPROTO=static IPADDR=192.168.40.200 NETMASK=255.255.255.0 GATEWAY=192.168.40.1 ONBOOT=yes }}} * /etc/sysconfig/network-scripts/ifcfg-eth1 {{{ DEVICE=eth1 BOOTPROTO=static IPADDR=192.168.50.200 NETMASK=255.255.255.0 GATEWAY=192.168.50.1 ONBOOT=yes }}} * service network restart {{{ Bringing up interface eth0: [ OK ] Bringing up interface eth1: [ OK ] }}} * 結果 => route {{{ Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.50.0 * 255.255.255.0 U 0 0 0 eth1 192.168.40.0 * 255.255.255.0 U 0 0 0 eth0 169.254.0.0 * 255.255.0.0 U 0 0 0 eth1 default 192.168.50.1 0.0.0.0 UG 0 0 0 eth1 }}} * この状態で、実際にWANへpingを送るとeth1を通る * tcpdump icmp -n -i eth1 {{{ listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes 01:32:42.314543 IP 192.168.50.200 > 219.94.129.108: ICMP echo request, id 16947, seq 1, length 64 01:32:42.330849 IP 219.94.129.108 > 192.168.50.200: ICMP echo reply, id 16947, seq 1, length 64 }}} * eth0とeth1を逆にしてみる * eth0 {{{ IPADDR=192.168.50.200 NETMASK=255.255.255.0 GATEWAY=192.168.50.1 }}} * eth1 {{{ IPADDR=192.168.40.200 NETMASK=255.255.255.0 GATEWAY=192.168.40.1 }}} * service network restart {{{ Bringing up interface eth0: [ OK ] Bringing up interface eth1: [ OK ] }}} * 結果 => route {{{ Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.50.0 * 255.255.255.0 U 0 0 0 eth0 192.168.40.0 * 255.255.255.0 U 0 0 0 eth1 169.254.0.0 * 255.255.0.0 U 0 0 0 eth1 default 192.168.40.1 0.0.0.0 UG 0 0 0 eth1 }}} * 今度もeth1を通る * tcpdump icmp -n -i eth1 {{{ listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes 01:39:05.380029 IP 192.168.40.200 > 219.94.129.108: ICMP echo request, id 26423, seq 1, length 64 01:39:05.392541 IP 219.94.129.108 > 192.168.40.200: ICMP echo reply, id 26423, seq 1, length 64 }}} * LinkUPの順番を変える * ifup eth1; ifup eth0 {{{ Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.50.0 * 255.255.255.0 U 0 0 0 eth0 192.168.40.0 * 255.255.255.0 U 0 0 0 eth1 169.254.0.0 * 255.255.0.0 U 0 0 0 eth0 default 192.168.50.1 0.0.0.0 UG 0 0 0 eth0 }}} * tcpdump icmp -n -i eth0 {{{ listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes 01:42:55.952191 IP 192.168.50.200 > 219.94.129.108: ICMP echo request, id 52536, seq 1, length 64 01:42:55.965580 IP 219.94.129.108 > 192.168.50.200: ICMP echo reply, id 52536, seq 1, length 64 }}} === sysconfig/network === * /etc/sysconfig/network {{{ GATEWAY=192.168.50.2 }}} * ifcfg-eth? に GATEWAY= があるとき * そちらが優先される * 無いとき * /etc/sysconfig/network の GATEWAY= が設定される {{{ Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.50.0 * 255.255.255.0 U 0 0 0 eth0 192.168.40.0 * 255.255.255.0 U 0 0 0 eth1 169.254.0.0 * 255.255.0.0 U 0 0 0 eth1 default 192.168.50.2 0.0.0.0 UG 0 0 0 eth0 }}} === 結論 === * /etc/sysconfig/network-scripts/ifcfg-eth? に GATEWAY= の指定がない場合は、/etc/sysconfig/network が参照される * ifcfg-eth? に GATEWAY= の指定がある際は、そちらが参照される * NICが複数ある場合は、最後にLinkUPしたデバイスのgatewayが有効になる ==== 例 ==== * eth0 {{{ GATEWAY=192.168.50.1 }}} * eth1 * 指定なし * network {{{ GATEWAY=192.168.50.2 }}} * => route {{{ default 192.168.50.1 0.0.0.0 UG 0 0 0 eth0 }}}