is on everything インターネット上の 2/3 以上のサーバーは Linux Android、ネットワーク機器、99 % のスパコン、IoT デバイス、Tesla cars、Play Station Linux is adaptable モジュール性があり OSS であるという性質から、様々な用途に使える Linux has a strong community and ecosystem OSS 故の協力なエコシステムがあり、学習にも向いている
# -i any: all devices # -nN: show ip addresses instead of host names $ sudo tcpdump <expression> –i any –nN # Write/read packets to/from file $ tcpdump –w dump.pcap –i any $ tcpdump –r dump.pcap # Filter health probes from Azure Load Balancer $ tcpdump –ni any host 168.63.129.16 and port <probe-port> and tcp
デフォルトで問い合わせる DNS サーバーは、DHCP で降ってきたり自分で設定した (おそらく キャッシュ) DNS サーバー • Azure VM の場合だと iDNS (168.63.129.16) が該当 • @ のオプションで問い合わせ先の DNS サーバーを変更することが出来る • キャッシュとかが気になるときは権威 DNS サーバーに問い合わせるようにする • BIND と呼ばれる DNS サーバーに関連するソフトウェア群に内包 • Berkeley Internet Name Domain で BIND • 4.3BSD で初めて実装されたソフトウェア
• net-tools (netstat/ifconfig/route/arp,…) のソフトウェアは廃止される方向 • ss や ip といった iproute2 の代替ツールを使うことが推奨されている • とはいえ他のエンジニアと話を合わせる為にも netstat を知っておかなければならない・・・ This program is mostly obsolete. Replacement for netstat is ss. Replacement for netstat –r is ip route. Replacement for netstat –i is ip –s link. Replacement for netstat –g is ip maddr. “ Ref: man netstat
Recommended (listening, tcp, udp, process, no-resolve) $ ss –ltupn # Show all TCP sockets connected to the local HTTPS port (443) $ ss –t src :443 # Show a summary of all ports connecting to 192.168.2.1 via port 80. $ ss -t dst 192.168.2.1:80 # Show all SSH-related TCP connections $ ss -t state established '( dport = :ssh or sport = :ssh )’ # Filter connections by TCP state $ ss -t4 state established|closed|time-wait|
address show up $ ip address show dev eth0 # Add/remove a secondary interface address to the device ‘eth0’ $ ip address add 10.0.0.10/24 dev eth0 $ ip address del 10.0.0.10/24 dev eth0 # Show all interfaces $ ip link show # Link-up/down $ ip link set eth0 up|down # Statistics # ip –s link
new table $ echo 100 newtable >> /etc/iproute2/rt_tables # Show policy rules $ ip rule show # Show routing table (default: main) $ ip route show # Show all routing table $ ip route show table all # Perform route lookup on the specific destination $ ip route get 10.0.0.4 # Show only IPv4/6 entries $ ip route -4 show $ ip route -6 show # Add/remove a route $ ip route add 192.168.0.0/24 via 192.168.0.1 dev eth0 $ ip route del 192.168.0.0/24 via 192.168.0.1 dev eth0
dev eth0 proto dhcp src 10.0.0.4 metric 100 10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.4 168.63.129.16 via 10.0.0.1 dev eth0 proto dhcp src 10.0.0.4 metric 100 169.254.169.254 via 10.0.0.1 dev eth0 proto dhcp src 10.0.0.4 metric 100 broadcast 10.0.0.0 dev eth0 table local proto kernel scope link src 10.0.0.4 local 10.0.0.4 dev eth0 table local proto kernel scope host src 10.0.0.4 broadcast 10.0.0.255 dev eth0 table local proto kernel scope link src 10.0.0.4 broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1 ... main table local table $1 (unicast|broadcast|local): エントリータイプ。unicast の場合は省略可能 $2 (x.x.x.x/x): 宛先アドレスプレフィクス $3 (via x.x.x.x): ネクストホップ。On-link の場合は省略可能 $4 (dev *): パケットが出力されるデバイス $5 (proto redirect|kernel|boot|static|ra): 誰がルートを作ったか。/etc/iproutue2/rt_protos で定義される PTPROTO のいずれか $6 (scope global|link|host|…): 宛先プレフィクスのスコープ。/etc/iproute2/rt_scopes のいずれか。省略すると global または link になる $7 (src x.x.x.x): 宛先に送信するときに優先して設定するソース IP アドレス $8 (metric *): ルートの優先度。小さい値のほうがより優先される
で配信されている情報や、インターフェイスの静的な config を確認することで、インター フェイス設定が間違っていないかチェックできる • CentOS 系: /etc/sysconfig/network-scripts/ifcfg-eth0 • Debian 系: /etc/network/interfaces • 特に Azure だと静的に IP アドレスを付与するのはご法度なので注意 $ sudo dhclient –v Listening on LPF/eth0/00:0d:3a:cc:e0:89 Sending on LPF/eth0/00:0d:3a:cc:e0:89 Sending on Socket/fallback DHCPREQUEST of 10.0.0.4 on eth0 to 255.255.255.255 port 67 (xid=0x56bd5864) DHCPACK of 10.0.0.4 from 168.63.129.16 RTNETLINK answers: File exists bound to 10.0.0.4 -- renewal in 4294967295 seconds.