トップ 一覧 検索 ヘルプ RSS ログイン

ネットワークの設定.debの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
{{category Debian}}
!!/etc/hostname

自分のホストネームだけが書かれたファイル。



!!/etc/resolv.conf

他のUNIXと同じ。



!!/etc/network/interfaces

その他の設定はすべてこのファイルに書けるので、見通しがいい。

 auto lo
 iface lo inet loopback
 
 auto eth0
 allow-hotplug eth0
 iface eth0 inet static
     address 192.168.1.100
     netmask 255.255.255.0
     gateway 192.168.1.1
 
 auto eth1
 allow-hotplug eth1
 iface eth1 inet dhcp

こんな感じ。

auto指定が無いと、OS起動時に有効にならない。
また少なくともlenny以降では、allow-hotplug指定が無いと、ifup や /etc/init.d/networking restart でインターフェースの起動がなされないので、付けておく。

起動時にルーティング・テーブルにエントリを追加できる。

 auto eth0
 allow-hotplug eth0
 iface eth0 inet static
     address 192.168.1.100
     netmask 255.255.255.0
     gateway 192.168.1.1
     up route add -net 172.16.1.0 netmask 255.255.255.0 gw 192.168.1.254

upコマンドの後ろに、route addをそのまま書くだけ。

その他オプションについては、

$ man 5 interfaces



!!2枚以上のNICでパケットをフォワードするには。

# sysctl -w net.ipv4.ip_forward=1

起動時にこれを自動的に行うためには、/etc/sysctl.confに

 net.ipv4.ip_forward = 1

と書いておく。

または、/etc/network/interfacesのオプションで、

 up sysctl net.ipv4.ip_forward=1

としておけばよいか。


!! NAT
Debian etch での iptables の設定。eth1が外、eth0が内とする。
とりあず、NATだけなので、
 iptables -F
 iptables -t nat -F
 iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

で、正常に動作することを確認。

iptables-save > /etc/iptables.conf

で、設定を保存して、/etc/network/interfaces に pre-up を追加。

 auto eth1
 iface eth1 inet dhcp
 
 auto eth0
 iface eth0 inet static
        address 192.168.0.254
        netmask 255.255.255.0
        pre-up iptables-restore < /etc/iptables.conf 


!! NetworkManagerの削除
NetworkManagerは、上記のように /etc/network/interfaces にいろいろ細工をしたい場合に設定が競合して反映されなかったりする。

あくまでクライアントPC向けの単純なネットワーク設定しかできないものと考えた方がよい。
NetworkManagerは、あくまでクライアントPC向けの単純なネットワーク設定しかできないものと考えた方がよい。
サーバー用途では、速攻でremoveして /etc/resolv.conf と /etc/network/interfaces を手動で設定しなおすのが吉と考える。

 # apt-get autoremove --purge network-manager