linux
あるとき突然今まで使っていたdockerコンテナで
ping: sendmsg: Operation not permitted
なるエラーでpingなどのネットワークツールがすべて使えなくなる問題が発生した。Dockerネットワーク
周りをはじめは疑ったのだが、実のところ
OpenVPNツールのキルスイッチの暴走でiptablesの内容が変更されてしまったことが原因であった。
Iptableの直し方はdockerでも生環境でも同じと思われる。
以下治ったときのコマンド例をメモ:
$ ping 8.8.8.8 # pingが飛ばなくなった PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. ping: sendmsg: Operation not permitted $ iptables -L # iptablesの内容を確認 Chain INPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere ACCEPT all -- 172.21.0.0/16 anywhere Chain FORWARD (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere 172.21.0.0/16 ACCEPT all -- 172.21.0.0/16 anywhere Chain OUTPUT (policy DROP) target prot opt source destination ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere 172.21.0.0/16 ACCEPT udp -- anywhere anywhere udp dpt:domain ACCEPT udp -- anywhere anywhere udp dpt:51820 ACCEPT tcp -- anywhere anywhere tcp dpt:openvpn ACCEPT udp -- anywhere anywhere udp dpt:openvpn ACCEPT tcp -- anywhere anywhere tcp dpt:https # ここからiptableの書き換え すべてのパケットを通すデフォルトを設定して初期化 $ iptables --policy INPUT ACCEPT $ iptables --policy FORWARD ACCEPT $ iptables --policy OUTPUT ACCEPT $ iptables -t nat --flush $ iptables -t mangle --flush $ iptables --flush $ iptables -X Chain INPUT (policy ACCEPT) target prot opt source destination Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination $ ping 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=56 time=13.4 msのようにするとpingが外部に通るようになって一件落着。
なおこれによってファイアウォールやパケットフィルタがすべて無効になって しまっているので、このあと必要なものを再設定するのがよい。