LoginSignup
1
0

More than 3 years have passed since last update.

VXLAN を使って、EC2 で Broadcast を試してみる

Last updated at Posted at 2019-12-19

たまーに、VPC内でブロードキャストを使いたい時があるのですが、対応していないので自力でなんとかする必要があります。
方法の一つとして VXLAN を利用できるので必要最小限のメモを残しておきます。

構成

  • シンプルに EC2(10.0.0.0/24) を2台用意
  • VXLAN を使って Overlay Network(192.168.1.0/24) を構築
  • 192.168.1.0/24 でブロードキャストをためす
  • OS は Amazon Linux 2

EC2-A

  • ENI IP: 10.0.12.137/24
  • vxlan interface ip: 192.168.1.1/24
  • AZ: us-east1-1c

EC2-B

  • ENI IP: 10.0.12.99/24
  • vxlan interface ip: 192.168.1.2/24
  • AZ: us-east1-1c

設定

本当に必要最小限の設定だけします。
それぞれのEC2で、vxlan interface を作成し、IPをつけます。

EC2-A
[ec2-user@ip-10-0-12-137 ~]$ sudo ip link add vxlan0 type vxlan id 10 dev eth0
[ec2-user@ip-10-0-12-137 ~]$ sudo ip addr add 192.168.1.1/24 broadcast 192.168.1.255 dev vxlan0
[ec2-user@ip-10-0-12-137 ~]$ sudo ip link set vxlan0 up
[ec2-user@ip-10-0-12-137 ~]$ sudo bridge fdb append 00:00:00:00:00:00 dev vxlan0 dst 10.0.12.99
[ec2-user@ip-10-0-12-137 ~]$ bridge fdb show
33:33:00:00:00:01 dev eth0 self permanent
01:00:5e:00:00:01 dev eth0 self permanent
33:33:ff:cd:b4:59 dev eth0 self permanent
00:00:00:00:00:00 dev vxlan0 dst 10.0.12.99 self permanent
EC2-B
[ec2-user@ip-10-0-12-99 ~]$ sudo ip link add vxlan0 type vxlan id 10 dev eth0
[ec2-user@ip-10-0-12-99 ~]$ sudo ip addr add 192.168.1.2/24 broadcast 192.168.1.255 dev vxlan0
[ec2-user@ip-10-0-12-99 ~]$ sudo ip link set vxlan0 up
[ec2-user@ip-10-0-12-99 ~]$ sudo bridge fdb append 00:00:00:00:00:00 dev vxlan0 dst 10.0.12.137
[ec2-user@ip-10-0-12-99 ~]$ bridge fdb show
33:33:00:00:00:01 dev eth0 self permanent
01:00:5e:00:00:01 dev eth0 self permanent
33:33:ff:5b:d5:2f dev eth0 self permanent
00:00:00:00:00:00 dev vxlan0 dst 10.0.12.137 self permanent

boradcast に ping 投げて動作確認しようと思うので "/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts" の値を変更しておきます。ただ、Smurf攻撃の対策のためにも、検証後は設定を戻しておきましょう。

Smurf攻撃
https://ja.wikipedia.org/wiki/Smurf%E6%94%BB%E6%92%83

EC2-A
[ec2-user@ip-10-0-12-137 ~]$ sudo sh -c 'echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts'
EC2-B
[ec2-user@ip-10-0-12-99 ~]$ sudo sh -c 'echo 0 >/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts'

動作確認

とりあえず、 ふつーに ping でユニキャストの通信確認してみます。
問題なく Overlay Network(192.168.1.0/24) で通信できてます。

EC2-B
[ec2-user@ip-10-0-12-99 ~]$ ping -b 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.281 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=0.222 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=0.205 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=255 time=0.185 ms

最後に、本題のブロードキャスト

EC2-B
[ec2-user@ip-10-0-12-99 ~]$ ping -b 192.168.1.255
WARNING: pinging broadcast address
PING 192.168.1.255 (192.168.1.255) 56(84) bytes of data.
64 bytes from 192.168.1.2: icmp_seq=1 ttl=255 time=0.017 ms
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=0.184 ms (DUP!)
64 bytes from 192.168.1.2: icmp_seq=2 ttl=255 time=0.027 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=0.293 ms (DUP!)
64 bytes from 192.168.1.2: icmp_seq=3 ttl=255 time=0.029 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=255 time=0.203 ms (DUP!)

お片づけ

/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts" の値を元に戻す

EC2-A
[ec2-user@ip-10-0-12-137 ~]$ sudo sh -c 'echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts'
EC2-B
[ec2-user@ip-10-0-12-99 ~]$ sudo sh -c 'echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_broadcasts'

以上です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0