GNU/Linux >> Linux の 問題 >  >> Cent OS

Centos – 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 結果–最後のクワッドが異なります)、
次にeth0 サイレントで、eth1にICMPエコーが表示されます 、予想どおり。

Linuxの2つの主要な種類で処理されるトラフィックのみを処理するように各インターフェイスを構成する方法を理解したいと思います。
もうすぐそこにいると思いますが、できることは何もありません。見つけたようです。

  • Debian Wheezy(7.x)またはDebian Jessie(8.x)
  • Enterprise Linux(6.x)(RedHat / CentOS / Scientific / Oracle)。

DebianのソリューションはWheezyとJessieの両方に適しているはずであり、
ELのソリューションはすべてのEL6.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

私のDebian8「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

承認された回答:

このトピックについてもっと知りたいので、構成を可能な限り最高のものに調整しますが、これまでのところ、これが私が持っているものです。すべてのネットワークインターフェイスでARPフィルタリングを有効にしなくても(net.ipv4.conf.all.arp_filter = 0 )、@ spukが述べたように、
この構成ではトラフィックが完全に分離されているようです。

関連:sedは改行から文字を削除しますか?

ファイル、/etc/iproute2/rt_tables 、少なくともEL6.xとDEB7/8では同じです。これは、静的ルートの名前付きルーティングテーブルを作成するファイルです。

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

上記の名前付き静的ルートの数252は、基本的に任意です。または、各静的ルートは1〜252の固有の番号を取得します。

ファイル、/etc/network/interfaces DEB 7/8では、少なくとも:

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 showの結果 Debianの場合:

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から取得されます。

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

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

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

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 showの結果 EL 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のアップデート

上記のこの方法は、RHEL6とRHEL7、および派生物で機能しますが、RHEL 8と派生物の場合は、最初にnetwork-scriptsをインストールする必要があります。 上記の方法を使用します。

dnf install network-scripts

インストールすると、network-scriptsという警告が表示されます RHELの次のメジャーリリースの1つで削除され、NetworkManagerがifupを提供します / ifdown スクリプトも。

Ubuntu20.04LTSのアップデート

名前付きルーティングテーブルの作成は問題ありませんが、netplanでは必須ではありません。 、とにかく名前を使用しません。それにもかかわらず、rt_tablesからの名前付きルーティングテーブルの数 ファイルはnetplanに使用できます 。対応するNICはenps03です。 (eth0 )および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

Cent OS
  1. CentOS 7 /RHEL7でネットワークブリッジを作成する方法

  2. CentOS / RHEL 7 :ネットワーク インターフェイス名を変更する方法

  3. CentOS 7 再起動ネットワーク コマンド

  1. 6tcpdumpネットワークトラフィックフィルターオプション

  2. CentOS8またはRHEL8でネットワークサービスを再起動する方法

  3. 2 つのインターフェース間のすべてのトラフィックをブロックする方法は?

  1. CentOS 8にWiresharkをインストールする-最良の方法は?

  2. CentOS7にVnStatネットワーク監視をインストールする方法

  3. CentOS / RHEL 7 で NetworkManager を無効にする方法