ネットワーク設定
ip, ss, NetworkManager
ipコマンド
ipコマンドはiproute2パッケージに含まれる 現代的なネットワーク管理ツール。従来のifconfig, route, arpの代替。
1 # インターフェース管理 2 ip addr # 全インターフェース表示 3 ip addr show eth0 # 特定インターフェース 4 ip link # リンク状態 5 ip link set eth0 up # インターフェースUP 6 ip link set eth0 down # インターフェースDOWN 7 8 # IPアドレス設定 9 ip addr add 192.168.1.10/24 dev eth0 10 ip addr del 192.168.1.10/24 dev eth0 11 12 # ルーティング 13 ip route # ルーティングテーブル 14 ip route add default via 192.168.1.1 15 ip route add 10.0.0.0/8 via 192.168.1.254 16 ip route del 10.0.0.0/8 17 18 # ARP/Neighbor 19 ip neigh # ARPテーブル 20 ip neigh add 192.168.1.1 lladdr aa:bb:cc:dd:ee:ff dev eth0 21 22 # 統計情報 23 ip -s link # パケット統計
ssコマンド
ss(Socket Statistics)はソケット情報を表示する netstatの後継ツール。より高速で詳細な情報を提供。
1 # 基本的な使い方 2 ss -tuln # TCPとUDPのリスニングポート 3 ss -tunp # 接続中ソケット(プロセス名付き) 4 ss -a # 全ソケット 5 6 # オプション 7 # -t: TCP 8 # -u: UDP 9 # -l: リスニング 10 # -n: 数値表示(名前解決なし) 11 # -p: プロセス情報 12 # -a: 全ソケット 13 14 # フィルタリング 15 ss -tn state established 16 ss -tn 'dport = :443' 17 ss -tn 'sport = :80' 18 19 # 統計 20 ss -s # ソケット統計サマリー 21 22 # 詳細情報 23 ss -ti # TCP内部情報(RTT, cwnd等)
NetworkManager
NetworkManagerはデスクトップ/サーバー向けの ネットワーク設定管理デーモン。CLIツールnmcliで操作可能。
1 # 接続一覧 2 nmcli connection show 3 4 # デバイス一覧 5 nmcli device status 6 7 # 接続UP/DOWN 8 nmcli connection up "Wired connection 1" 9 nmcli connection down "Wired connection 1" 10 11 # 新規接続作成 12 nmcli connection add type ethernet con-name eth0-static ifname eth0 \ 13 ip4 192.168.1.10/24 gw4 192.168.1.1 14 15 # 設定変更 16 nmcli connection modify eth0-static ipv4.dns "8.8.8.8 8.8.4.4" 17 nmcli connection modify eth0-static ipv4.method manual 18 19 # インタラクティブ編集 20 nmcli connection edit "Wired connection 1" 21 22 # Wi-Fi 23 nmcli device wifi list 24 nmcli device wifi connect "SSID" password "password"
Netplan (Ubuntu)
Ubuntu 18.04以降のネットワーク設定。YAMLファイルで定義し、 NetworkManagerまたはsystemd-networkdに適用。
1 # /etc/netplan/01-netcfg.yaml 2 network: 3 version: 2 4 renderer: networkd # または NetworkManager 5 ethernets: 6 eth0: 7 dhcp4: false 8 addresses: 9 - 192.168.1.10/24 10 gateway4: 192.168.1.1 11 nameservers: 12 addresses: 13 - 8.8.8.8 14 - 8.8.4.4
1 # 設定適用 2 sudo netplan apply 3 4 # テスト(問題があれば自動ロールバック) 5 sudo netplan try 6 7 # デバッグ 8 sudo netplan --debug apply
カーネルネットワークパラメータ
1 # IP転送有効化 2 sysctl -w net.ipv4.ip_forward=1 3 4 # 永続化(/etc/sysctl.conf) 5 net.ipv4.ip_forward = 1 6 7 # 主要なパラメータ 8 # net.ipv4.ip_forward - IPルーティング 9 # net.ipv4.tcp_syncookies - SYN flood対策 10 # net.ipv4.tcp_max_syn_backlog - SYNキュー最大値 11 # net.core.somaxconn - listenバックログ最大値 12 # net.core.netdev_max_backlog - 受信キュー最大値 13 # net.ipv4.tcp_tw_reuse - TIME_WAIT再利用 14 15 # 現在値確認 16 sysctl net.ipv4.ip_forward 17 18 # 全パラメータ表示 19 sysctl -a | grep net.ipv4
SRE/インフラ観点
高負荷サーバーのチューニング
- •
net.core.somaxconn: 65535 - •
net.ipv4.tcp_max_syn_backlog: 65535 - •
net.ipv4.tcp_tw_reuse: 1 - •
net.core.netdev_max_backlog: 65535
トラブルシューティング
- • リンクダウン:
ip link,dmesg - • IP重複:
arping - • 接続タイムアウト:
ss -tnでTIME_WAIT確認