2 つのネットワークインターフェイスで別々のネットワークトラフィック

2 つのネットワークインターフェイスで別々のネットワークトラフィック

専門知識を活用して、両方のネットワークインターフェイスでネットワークトラフィック分離を設定する方法を理解できますか?

私が知っている限り、これまでデフォルトゲートウェイを使用するように設計されていなかったネットワークトラフィックには固定パスが使用されていました。デフォルトゲートウェイは、ローカルネットワークに向かうのではなく、ルーティングテーブルにデフォルトルートが割り当てられていないすべてのトラフィックに使用されます。

シナリオは次のとおりです。

  • ネットワーク内の各コンピュータには2つのネットワークカードがあります。
  • 各プロダクション インターフェイスはeth0(GW = 10.10.10.1) です。
  • それぞれの管理インターフェイスはeth1(GW = 192.168.100.1)です。
  • 生産および管理トラフィックは完全に分離する必要があります。

私はDebian Wheezyで試したことを以下に投稿しました。そして私の問題は、両方のインターフェイスで通信するようにホストを設定しましたが、個々のホストが間違ったインターフェイスのトラフィックを「聞く」ように見えることです。たとえば、

ホスト140

eth0      Link encap:Ethernet  HWaddr 08:00:27:d1:b6:8f
          inet addr:10.10.10.140  Bcast:10.10.10.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fed1:b68f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1341 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2530 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:641481 (626.4 KiB)  TX bytes:241124 (235.4 KiB)

eth1      Link encap:Ethernet  HWaddr 08:00:27:ad:14:b6
          inet addr:192.168.100.140  Bcast:192.168.100.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fead:14b6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7220 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5257 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:602485 (588.3 KiB)  TX bytes:1022906 (998.9 KiB)

ホスト140で次のコマンドを実行しますtcpdump -i eth0。ホスト140の別のセッションでping 192.168.100.50

19:17:29.301565 IP 192.168.100.140 > 192.168.100.50: ICMP echo request, id 1400, seq 10, length 64
19:17:30.301561 IP 192.168.100.140 > 192.168.100.50: ICMP echo request, id 1400, seq 11, length 64
19:17:31.301570 IP 192.168.100.140 > 192.168.100.50: ICMP echo request, id 1400, seq 12, length 64
19:17:32.301580 IP 192.168.100.140 > 192.168.100.50: ICMP echo request, id 1400, seq 13, length 64

上記の出力がで表示されるのはなぜですかeth0? 10.10.10.140のトラフィックのみを表示できるはずです。予想通り、以下でもこの内容を見ましたeth1

19:18:47.805408 IP 192.168.100.50 > 192.168.100.140: ICMP echo request, id 1605, seq 247, length 64

ホスト50でpingを実行すると(ifconfig同じ結果 - 最後のクワッドのみが異なる)、予想通り静かでeth0ICMP echoが表示されますeth1

両方の主要なLinuxバージョンが担当するトラフィックのみを処理するように各インターフェイスを設定する方法を知りたいです。ほとんどやってきたようですが、見つからない何かが抜けましたね。

  • Debian Wheezy(7.x) または Debian Jessie(8.x)
  • エンタープライズLinux(6.x)(RedHat/CentOS/Scientific/Oracle)。

私はDebianソリューションがWheezyとJessieの両方に適している必要があり、ELソリューションがすべてのEL 6.xバージョンで同じであることを知っています。コマンドを実行するためにRCスクリプトを使用することを避け、代わりに設定ファイルを使用したいと思います。

Debian で私が知っている関連設定ファイルは次のようになります。

  • /etc/network/interfaces

EL 6.xで私が知っている関連設定ファイルは次のとおりです。

  • /etc/sysconfig/network
  • /etc/sysconfig/network-scripts/ifcfg-eth0
  • /etc/sysconfig/network-scripts/ifcfg-eth1
  • /etc/sysconfig/network-scripts/route-eth0
  • /etc/sysconfig/network-scripts/route-eth1
  • /etc/sysconfig/network-scripts/rule-eth0
  • /etc/sysconfig/network-scripts/rule-eth1

私のDebian 8 "Jessie"/etc/network/interfacesファイル:

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# Production interface
auto eth0
allow-hotplug eth0
iface eth0 inet static
  address 10.10.10.140
  netmask 255.255.255.0
  gateway 10.10.10.1

# Management interface
auto eth1
allow-hotplug eth1
iface eth1 inet static
  address 192.168.100.140
  netmask 255.255.255.0

netstat -anr私はこれが問題を説明できると思います。

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.10.10.1      0.0.0.0         UG        0 0          0 eth0
10.10.10.0      0.0.0.0         255.255.255.0   U         0 0          0 eth0
192.168.100.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0
192.168.100.0   0.0.0.0         255.255.255.0   U         0 0          0 eth1

ベストアンサー1

構成を最適な構成に最適化するために、このトピックについてさらに詳しく知りたいのですが、これがこれまでの内容です。 @spukが述べたように、すべてのネットワークインターフェイス()でARPフィルタリングを有効にしなくても、net.ipv4.conf.all.arp_filter = 0この設定ではトラフィックが完全に分離されているようです。

/etc/iproute2/rt_tables少なくともEL 6.xとDEB 7/8では、ファイルは同じです。これは、静的パスの名前付きルーティングテーブルを生成するファイルです。

#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
252 mgmt

上述の固定経路の数である252は本質的に任意である。または、各固定パスには固有の番号(1〜252)があります。

DEB 7/8 のファイルには、/etc/network/interfaces少なくとも以下が含まれます。

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
  iface lo inet loopback

# The production network interface
# The 'gateway' directive is the default route.
# Were eth0 configured via DHCP, the default route would also be here.
auto eth0
allow-hotplug eth0
iface eth0 inet static
  address 10.10.10.140
  netmask 255.255.255.0
  gateway 10.10.10.1

# The management network interface
# The 'gateway' directive cannot be used again because there can be
# one, and only one, default route. Instead, the 'post-up' directives
# use the `mgmt` static route.
auto eth1
allow-hotplug eth1
iface eth1 inet static
  address 192.168.100.140
  netmask 255.255.255.0
  post-up ip route add 192.168.100.0/24 dev eth1 src 192.168.100.140 table mgmt
  post-up ip route add default via 192.168.100.1 dev eth1 table mgmt
  post-up ip rule add from 192.168.100.140/32 table mgmt
  post-up ip rule add to 192.168.100.140/32 table mgmt

ip route showDebian での結果:

default via 10.10.10.1 dev eth0
10.10.10.0/24 dev eth0  proto kernel  scope link  src 10.10.10.140
192.168.100.0/24 dev eth1  proto kernel  scope link  src 192.168.100.140

EL 6.x/etc/sysconfig/networkファイル:

NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=10.10.10.1

上記では、GATEWAYがデフォルトパスです。次に、BOOTPROTOCOLがDHCPに設定されている場合、デフォルトパスはDHCPから取得されます。

「HWADDR」と「UUID」のないEL 6.x/etc/sysconfig/network-scripts/ifcfg-eth0ファイル:

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=10.10.10.140
NETMASK=255.255.255.0
NETWORK=10.10.10.0
BROADCAST=10.10.10.255

「HWADDR」と「UUID」のないEL 6.x/etc/sysconfig/network-scripts/ifcfg-eth1ファイル:

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTOCOL=none
IPADDR=192.168.100.140
NETMASK=255.255.255.0
NETWORK=192.168.100.0
BROADCAST=192.168.100.255

EL 6.x/etc/sysconfig/network-scripts/route-eth1ファイル:

192.168.100.0/24 dev eth1 table mgmt
default via 192.168.100.1 dev eth1 table mgmt

EL 6.x/etc/sysconfig/network-scripts/rule-eth1ファイル:

from 192.168.100.0/24 lookup mgmt

ip route showEL 6.xの結果:

192.168.100.0/24 dev eth1  proto kernel  scope link  src 192.168.100.160
10.10.10.0/24 dev eth0  proto kernel  scope link  src 10.10.10.160
default via 10.10.10.1 dev eth0

RHEL8アップデート

上記の方法はRHEL 6、RHEL 7およびその派生バージョンに適していますが、RHEL 8およびその派生バージョンの場合は、上記のnetwork-scripts方法を使用する前に最初にインストールする必要があります。

dnf install network-scripts

network-scriptsインストールすると、RHELの次のメジャーバージョンの1つから削除される警告が生成され、NetworkManagerはifup/ifdownスクリプトも提供します。

Ubuntu 20.04 LTSアップデート

名前付きパステーブルを作成するのは問題ありませんが、使用する必要はなく、netplanとにかく名前を使用しません。それにもかかわらず、ファイルで指定されたルーティングテーブル番号は引き続きrt_tables使用できますnetplan。対応するネットワークカードはenps03eth0)とenp0s8eth1)です。

network:
  version: 2
  ethernets:
    enp0s3:
      addresses:
      - 10.10.10.140/24
      dhcp4: false
      dhcp6: false
      gateway4: 10.10.10.1
      nameservers:
        addresses:
        - 1.2.3.4
        - 1.2.3.5
        search:
        - your-search-domain-name.com
    enp0s8:
      dhcp4: false
      dhcp6: false
      addresses:
      - 192.168.100.140/24
      routes:
      - to: 192.168.100.0/24
        via: 192.168.100.1
        table: 252
      routing-policy:
      - from: 192.168.100.0/24
        table: 252

これにより、次のパスが作成されますip r s

default via 10.10.10.1 dev enp0s3 proto static
10.10.10.0/24 dev enp0s3 proto kernel scope link src 10.10.10.140
192.168.100.0/24 dev enp0s8 proto kernel scope link src 192.168.100.140

おすすめ記事