
静的 IP を持つ既存のネットワーク (192.168.1.) が存在する物理層に、DHCP 対応ネットワーク (192.168.2.) を構成する必要があります。2 つのインターフェイス (サーバーとインターフェイスはすべて仮想) を備えた Debian 7 サーバーがあり、ネットワークのゲートウェイとして IP を設定したいと考えています。元のネットワークにパケットをルーティングするために eth0 を使用し (192.168.1.5 のインターネット ゲートウェイにアクセスするため)、ネットワークとの間のトラフィックを処理するために eth1 を使用しました。
ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:d4:02:1b
inet addr:192.168.1.110 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed4:21b/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:21668983 errors:0 dropped:0 overruns:0 frame:0
TX packets:10044848 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10931368249 (10.1 GiB) TX bytes:2383839079 (2.2 GiB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:d4:02:25
inet addr:192.168.2.1 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fed4:225/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14113604 errors:0 dropped:0 overruns:0 frame:0
TX packets:11269734 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1871598524 (1.7 GiB) TX bytes:10331981618 (9.6 GiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8158 errors:0 dropped:0 overruns:0 frame:0
TX packets:8158 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:629690 (614.9 KiB) TX bytes:629690 (614.9 KiB)
ルート
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.1.5 0.0.0.0 UG 0 0 0 eth0
localnet * 255.255.255.0 U 0 0 0 eth0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth1
iptables -vL
Chain INPUT (policy ACCEPT 5603K packets, 822M bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy DROP 138K packets, 8597K bytes)
pkts bytes target prot opt in out source destination
14M 9542M ACCEPT all -- any any anywhere anywhere state RELATED,ESTABLISHED
398K 27M ACCEPT all -- eth1 any anywhere anywhere
Chain OUTPUT (policy ACCEPT 2915K packets, 1432M bytes)
pkts bytes target prot opt in out source destination
iptables -tnat -vL
Chain PREROUTING (policy ACCEPT 607K packets, 49M bytes)
pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 112K packets, 17M bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 6893 packets, 977K bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 2391 packets, 374K bytes)
pkts bytes target prot opt in out source destination
363K 24M MASQUERADE all -- any eth0 anywhere anywhere
その後、eth1 で権威 DHCP サーバーを有効にしました。
ここで問題があります。サーバーとの接続は常に機能していますが (Samba 共有と MySQL サーバーがそこにあります)、時々 (ランダムのようですが)、クライアント (主に Windows 7 または XP) が一定時間インターネットに接続できなくなります。この状態では、192.168.1.110 には ping できますが、192.168.1.5 には ping できません。
補遺
FORWARD チェーンがパケットをドロップしたという事実は疑わしいと思われるため、次のようにしてそのフィルタリングを一時的に無効にしました。
iptables -A FORWARD -j ACCEPT
この新しいルールが導入されると、すべてが機能します。ただし、何が起こっているのかまだ明確にする必要があります...
補遺2
実際の iptables ルールは次のとおりです。
iptables 保存
# Generated by iptables-save v1.4.14 on Fri Jun 27 20:53:32 2014
*mangle
:PREROUTING ACCEPT [28129147:14012989399]
:INPUT ACCEPT [8479051:1218948772]
:FORWARD ACCEPT [19639349:12792010625]
:OUTPUT ACCEPT [4434912:3183821941]
:POSTROUTING ACCEPT [23940877:15968783924]
COMMIT
# Completed on Fri Jun 27 20:53:32 2014
# Generated by iptables-save v1.4.14 on Fri Jun 27 20:53:32 2014
*nat
:PREROUTING ACCEPT [931027:74896097]
:INPUT ACCEPT [153578:23398245]
:OUTPUT ACCEPT [9169:1292388]
:POSTROUTING ACCEPT [3186:492868]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Fri Jun 27 20:53:32 2014
# Generated by iptables-save v1.4.14 on Fri Jun 27 20:53:32 2014
*filter
:INPUT ACCEPT [2415796:331288771]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [1218435:1654003511]
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth1 -j ACCEPT
-A FORWARD -j ACCEPT
COMMIT
# Completed on Fri Jun 27 20:53:32 2014
答え1
パケットが iptables チェーンを介してどこに流れているかを診断するには、-j LOG パラメータを使用し、最終的には --log-prefix「kern.log または syslog でログを簡単に識別できるテキスト」を使用します。デフォルトの Accept ポリシーを使用し、ログ記録を有効にして FORWARD チェーンの最後にすべての拒否ルールを追加することで、ドロップされているパケットの種類をよりよく理解できるようになります。
この回路図を見てみて下さいhttp://www.linuxnetmag.com/share/issue9/iptables3.jpg、iptables チェーン内のパケットの基本的なフローを示します。
より良い回答を得るために、定義した完全な iptable ルールを用意しておくと興味深いでしょう。