
ケース想像する(カリLinuxRaspBerry Pi 2 B+のv2:
luis@Fresoncio:~$ sudo route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.18.25.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 100 0 0 eth1
default 192.168.35.100 0.0.0.0 UG 101 0 0 eth2
... etc (see full table below)
イーサネット(RJ45ケーブル)カード(NIC):
luis@Fresoncio:~$ sudo ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.25.246 netmask 255.255.255.0 broadcast 172.18.25.255
inet6 fe80::ba27:ebff:fe92:feb3 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:92:fe:b3 txqueuelen 1000 (Ethernet)
RX packets 3013014 bytes 296362931 (282.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9910966 bytes 558782777 (532.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.33 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::b117:1000:39bb:f8f0 prefixlen 64 scopeid 0x20<link>
ether a0:ce:c8:09:e3:ef txqueuelen 1000 (Ethernet)
RX packets 97636 bytes 7342211 (7.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 471 bytes 31163 (30.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.35.104 netmask 255.255.255.0 broadcast 192.168.35.255
inet6 fe80::805b:dfe3:8c3b:61ff prefixlen 64 scopeid 0x20<link>
ether a0:ce:c8:09:f8:84 txqueuelen 1000 (Ethernet)
RX packets 276507 bytes 18134656 (17.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 215 bytes 19996 (19.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 96 bytes 12362 (12.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 96 bytes 12362 (12.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
--- etc (see fulll table below)
このコンピュータにあるものを見ることができます。ネットワークカード3枚。インターネットでpingを実行すると動作します。NIC を指定する場合は、以下をすべて使用してください。
luis@Fresoncio:~$ sudo ping -I eth0 -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 172.18.25.246 eth0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=36.7 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=308 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=85.5 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=54 time=151 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=54 time=56.6 ms
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 36.753/127.695/308.472/98.316 ms
luis@Fresoncio:~$ sudo ping -I eth1 -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.1.33 eth1: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=43.3 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=41.0 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=40.7 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=55 time=41.5 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=55 time=40.9 ms
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 40.757/41.517/43.303/0.962 ms
luis@Fresoncio:~$ sudo ping -I eth2 -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.35.104 eth2: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=50.7 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=37.4 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=49.2 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=55 time=37.7 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=55 time=53.2 ms
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 37.499/45.711/53.250/6.723 ms
今失敗事例想像する(Ubuntu v16ノートパソコンの場合):
luis@Hipatio:~$ sudo route
Tabla de rutas IP del núcleo
Destino Pasarela Genmask Indic Métric Ref Uso Interfaz
default Router- 0.0.0.0 UG 0 0 0 enp2s0
default 192.168.22.1 0.0.0.0 UG 100 0 0 enx3c18a00b753d
link-local * 255.255.0.0 U 1000 0 0 enp2s0
192.168.11.0 * 255.255.255.0 U 0 0 0 enp2s0
192.168.22.0 * 255.255.255.0 U 100 0 0 enx3c18a00b753d
今回最も重点を置くのはRJ45ケーブルNIC 2本:
luis@Hipatio:~$ ifconfig
enp2s0 Link encap:Ethernet direcciónHW 68:f7:28:d2:a4:ce
Direc. inet:192.168.11.119 Difus.:192.168.11.255 Másc:255.255.255.0
Dirección inet6: fe80::6af7:28ff:fed2:a4ce/64 Alcance:Enlace
ACTIVO DIFUSIÓN FUNCIONANDO MULTICAST MTU:1500 Métrica:1
Paquetes RX:454517 errores:0 perdidos:0 overruns:0 frame:0
Paquetes TX:1940326 errores:0 perdidos:0 overruns:0 carrier:0
colisiones:0 long.colaTX:1000
Bytes RX:73243397 (73.2 MB) TX bytes:2778755895 (2.7 GB)
enx3c18a00b753d Link encap:Ethernet direcciónHW 3c:18:a0:0b:75:3d
Direc. inet:192.168.22.51 Difus.:192.168.22.255 Másc:255.255.255.0
Dirección inet6: fe80::4c9d:de01:a97a:fd42/64 Alcance:Enlace
ACTIVO DIFUSIÓN FUNCIONANDO MULTICAST MTU:1500 Métrica:1
Paquetes RX:194 errores:0 perdidos:0 overruns:0 frame:0
Paquetes TX:355 errores:0 perdidos:0 overruns:0 carrier:0
colisiones:0 long.colaTX:1000
Bytes RX:20096 (20.0 KB) TX bytes:39265 (39.2 KB)
lo Link encap:Bucle local
Direc. inet:127.0.0.1 Másc:255.0.0.0
Dirección inet6: ::1/128 Alcance:Anfitrión
ACTIVO BUCLE FUNCIONANDO MTU:65536 Métrica:1
Paquetes RX:60 errores:0 perdidos:0 overruns:0 frame:0
Paquetes TX:60 errores:0 perdidos:0 overruns:0 carrier:0
colisiones:0 long.colaTX:1
Bytes RX:5099 (5.0 KB) TX bytes:5099 (5.0 KB)
この時間失敗する(応答なし)ネイティブではないNICからpingを送信する場合:
luis@Hipatio:~$ ping -I enx3c18a00b753d -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.22.51 enx3c18a00b753d: 56(84) bytes of data.
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 3999ms
これデフォルトでは1つが有効です。いいね:
luis@Hipatio:~$ ping -I enp2s0 -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 192.168.11.119 enp2s0: 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=51.6 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=52.9 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=55 time=50.9 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=55 time=50.8 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=55 time=51.0 ms
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 50.812/51.498/52.995/0.826 ms
luis@Hipatio:~$ ping -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=51 time=57.9 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=51 time=57.0 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=51 time=57.0 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=51 time=57.1 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=51 time=57.6 ms
同じテストやはり失敗した存在するRaspBerry Pi 2 B+用Ubuntu Mate v16(今回はRJ45ネットワークカード4枚):基本カードのみ機能します。だから私は問題がUbuntuにあるべきかどうか疑問に思います(このpingテストはv14のような古いUbuntuバージョンのものであると確信しています)。とにかく、Linuxの問題を解決する方法を知ることは私にとって最善のことです。
ここで何が起こっているのですか?特定のNICでping?
注1:最初の例のKaliジョブディストリビューションでは、複数のVPNが同時に動作するため(読み取りがやや混乱しているため)テーブルを削除しましたroute
。フルバージョンは次のとおりです(必要ありませんが…誰がわかりますか?)。
luis@Fresoncio:~$ sudo route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.18.25.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 100 0 0 eth1
default 192.168.35.100 0.0.0.0 UG 101 0 0 eth2
115.red-79-157- 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
67.red-79-157-8 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
187.red-81-32-1 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
227.red-81-32-1 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
82.red-81-33-18 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
190.red-83-44-1 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
152.red-83-44-2 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
249.red-83-44-2 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
10.red-83-52-23 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
172.red-83-52-2 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
206.red-83-52-2 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
33.244.222.87.d 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
32.246.222.87.d 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
235.248.222.87. 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
151.18.16.95.dy 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
196.48.16.95.dy 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
143.49.16.95.dy 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
189.54.16.95.dy 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
122.56.16.95.dy 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
11.81.20.95.dyn 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
237.204.22.95.d 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
177.206.22.95.d 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
163.red-95-123- 172.18.25.1 255.255.255.255 UGH 0 0 0 eth0
172.18.25.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
192.168.35.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
192.168.35.0 0.0.0.0 255.255.255.0 U 100 0 0 eth2
192.168.210.0 0.0.0.0 255.255.255.0 U 0 0 0 ppp0
192.168.211.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
...これが完了しましたifconfig
。
luis@Fresoncio:~$ sudo ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.25.246 netmask 255.255.255.0 broadcast 172.18.25.255
inet6 fe80::ba27:ebff:fe92:feb3 prefixlen 64 scopeid 0x20<link>
ether b8:27:eb:92:fe:b3 txqueuelen 1000 (Ethernet)
RX packets 3018864 bytes 296745295 (282.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9911793 bytes 558868110 (532.9 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.33 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::b117:1000:39bb:f8f0 prefixlen 64 scopeid 0x20<link>
ether a0:ce:c8:09:e3:ef txqueuelen 1000 (Ethernet)
RX packets 97908 bytes 7362465 (7.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 480 bytes 31821 (31.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.35.104 netmask 255.255.255.0 broadcast 192.168.35.255
inet6 fe80::805b:dfe3:8c3b:61ff prefixlen 64 scopeid 0x20<link>
ether a0:ce:c8:09:f8:84 txqueuelen 1000 (Ethernet)
RX packets 277209 bytes 18180584 (17.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 223 bytes 20612 (20.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 96 bytes 12362 (12.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 96 bytes 12362 (12.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1446
inet 192.168.210.141 netmask 255.255.255.0 destination 192.168.210.1
ppp txqueuelen 3 (Point-to-Point Protocol)
RX packets 461 bytes 43679 (42.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 423 bytes 90174 (88.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
inet 192.168.211.141 netmask 255.255.255.0 destination 192.168.211.141
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 100 (UNSPEC)
RX packets 14 bytes 704 (704.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ノート2:新しい手がかり。研究を通して見つけたものマルチルーティング機能このオプションは必須CONFIG_IP_MROUTE_MULTIPLE_TABLES
です。CONFIG_IP_MULTIPLE_TABLES
コア。
これが出力である限り、私はこれが疑わしいです。失敗するコンピュータ:
luis@Hipatio:/usr/src/linux-headers-4.4.0-62-generic$ cat .config | grep "multiple" -i
# CONFIG_OPROFILE_EVENT_MULTIPLEX is not set
CONFIG_NEED_MULTIPLE_NODES=y
CONFIG_IP_MULTIPLE_TABLES=y
# CONFIG_IP_MROUTE_MULTIPLE_TABLES is not set
CONFIG_IPV6_MULTIPLE_TABLES=y
CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
# Multiplexer I2C Chip support
これは布材コンピュータ:
luis@Fresoncio:/usr/src/kernel$ cat .config | grep "multiple" -i
CONFIG_IP_MULTIPLE_TABLES=y
CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
CONFIG_IPV6_MULTIPLE_TABLES=y
CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
CONFIG_DEVPTS_MULTIPLE_INSTANCES=y
# Multiplexer I2C Chip support
ノート3:テスト済み(またはそう思います)メソッドリファレンスノート2/etc/default/grub
行を変更すると、次のようになります。
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash CONFIG_IP_MROUTE_MULTIPLE_TABLES=y"
ご覧のとおり、システムは次のパラメータで始まりますyes
。
luis@Hipatio:~$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.4.0-62-generic root=UUID=66464d51-851f-4623-b5cb-1699901a4a9b ro quiet splash CONFIG_IP_MROUTE_MULTIPLE_TABLES=y vt.handoff=7
残念ながら結果がない。 pingはまだ失敗します。
答え1
デフォルトでは、システムは実際には指定された宛先に対して 1 つのパスを使用します。これは、ip route get 8.8.8.8
前のコマンドで示されたパケットではなく、インターフェイスからパケットを受信した場合、一種のなりすましの試みと見なされます。そしてそれを破棄してください。リバースパスフィルタリングが無効になっている場合、次の操作は実行されません。
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/enx3c18a00b753d/rp_filter.
可能であれば、常にデフォルトパスを使用することが可能であり、緩いモードが望ましいです(値2を使用し、enp2s0には1を残します)。
あなたのコメントに関して、enp2s0には競争条件はありません。ルーティングテーブルは、これらの設定によって変更または変更されないため、競合は発生しません。よりip-sysctl.txt Linuxカーネルドキュメント 詳細については。
今、あなたの目標のために、これは実際にやるべきことではありません。パスを設定する必要があります。テーブルインターフェース/プロバイダー別およびソースIP(しかし、これはCONFIG_IP_MULTIPLE_TABLESの目的です。CONFIG_IP_MROUTE *はマルチキャスト用です。)その後、いくつかの選択ロジックを使用してください。ip
rule
注文する。 1つ以上の可能性があります。例えばiptablesを使用してパケットを表示し、その表示をより多くのパスに使用するルールあるいは、例のいずれかのように、特定の宛先への特定のパスを設定する方がはるかに簡単です(終了を参照)。
すべての詳細には例が含まれています。
http://lartc.org/howto/lartc.rpdb.multiple-links.html
ここに直接実際の例を入れるのはやや長いが、従いやすいようです(一部の注意事項など含む)。この場合、ルーティングアルゴリズムが以前と同じくらい簡単ではない場合でも、パケットは常に予想されるインターフェイスを介して到着するため、rp_filterを変更する必要はなくなります。
パスベースのロードバランシングの例とは異なり、そのタスクが完了したら、iptablesを使用してタスクを実行できます。たとえば、natテーブルのstatistic
モジュールを組み合わせて--every
使用する複数のSNAT(プロバイダごとに1つ)を使用して、すべての新しい接続の負荷を動的に分散します。