この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:5
ページ更新者:T
更新日時:2026-06-11 07:12:00

タイトル: ip IPアドレスの確認
SEOタイトル: Linux で IP アドレスを確認するコマンド完全ガイド(ip / ifconfig / hostname)

この記事の要点
  • 現代の標準: ip addr show(または短縮形 ip a
  • 旧来のコマンド: ifconfignet-tools パッケージ、最近の distro では非インストール)
  • 素早く IPv4 だけ: hostname -I
  • インターフェース指定: ip addr show eth0 / ip -4 a(IPv4 のみ)
  • 経路 / デフォルトゲートウェイ: ip route / ip route show default
  • Windows: ipconfig / PowerShell Get-NetIPAddress

ip コマンド(最新標準)

ipiproute2 パッケージのコマンドで、ネットワーク設定の現代の標準です。RHEL 7+ / Ubuntu 16.04+ では既定インストール。

# 全インターフェース表示
ip addr show
ip address show
ip a                       # 短縮形

# 出力例
# 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 ...
#     inet 127.0.0.1/8 scope host lo
#     inet6 ::1/128 scope host
# 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
#     link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
#     inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic eth0
#     inet6 fe80::211:22ff:fe33:4455/64 scope link

# IPv4 のみ
ip -4 addr show
ip -4 a

# IPv6 のみ
ip -6 addr show

# 簡潔な 1 行表示
ip -br addr show
# 出力例:
# lo               UNKNOWN        127.0.0.1/8 ::1/128
# eth0             UP             192.168.1.10/24 fe80::.../64

インターフェース指定

# 特定インターフェースだけ
ip addr show eth0
ip a show eth0
ip a eth0           # show 省略可

# 名前で grep
ip addr show | grep -E '^[0-9]+:|inet '

# インターフェース一覧だけ
ip link show
ip -br link show
ls /sys/class/net/

ifconfig(旧来のコマンド)

ifconfignet-tools パッケージに含まれる旧コマンド。RHEL 8+ / Ubuntu 18.04+ では既定では入っていませんが、まだ多くのドキュメントで使われています。

# インストール(必要なら)
sudo apt install net-tools           # Ubuntu/Debian
sudo dnf install net-tools           # RHEL/CentOS

# 全インターフェース
ifconfig
ifconfig -a                          # ダウン中の IF も表示

# 特定インターフェース
ifconfig eth0

# 出力例
# eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
#         inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
#         inet6 fe80::211:22ff:fe33:4455  prefixlen 64  scopeid 0x20<link>
#         ether 00:11:22:33:44:55  txqueuelen 1000  (Ethernet)

素早く IP だけ取り出す

# IPv4 だけ複数行で
hostname -I                          # 192.168.1.10 10.0.0.5

# 1 つ目だけ取り出し
hostname -I | awk '{print $1}'

# eth0 の IPv4 を変数に
IP=$(ip -4 -br addr show eth0 | awk '{print $3}' | cut -d/ -f1)
echo $IP

# 別解
ip -4 -o addr show eth0 | awk '{print $4}' | cut -d/ -f1

外部から見た IP(グローバル IP)

NAT 配下のサーバーで「インターネットから見た自分の IP」を知りたい場合:

# 公開サービスを使う
curl ifconfig.me
curl ifconfig.io
curl icanhazip.com
curl ipinfo.io/ip
curl -s https://api.ipify.org

# DNS 経由(高速)
dig +short myip.opendns.com @resolver1.opendns.com
nslookup myip.opendns.com resolver1.opendns.com

経路 / デフォルトゲートウェイ

# ルーティングテーブル
ip route show
ip route
ip r              # 短縮

# 出力例
# default via 192.168.1.1 dev eth0 proto dhcp metric 100
# 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10

# デフォルトゲートウェイだけ
ip route show default
ip route | awk '/default/ {print $3}'

# 特定の宛先がどの経路を使うか
ip route get 8.8.8.8
# → 8.8.8.8 via 192.168.1.1 dev eth0 src 192.168.1.10

# 旧コマンドでは
route -n
netstat -rn

DNS / ネットワーク全体確認

# DNS サーバー
cat /etc/resolv.conf
resolvectl status            # systemd-resolved

# hostname
hostname
hostname -f                  # FQDN
hostname -I                  # IP

# 全部入り(最近の RHEL/Ubuntu)
nmcli                        # NetworkManager
nmcli device show

# 詳細情報
ss -tlnp                     # LISTEN 中のソケット(netstat -tlnp の代替)
ss -tunp                     # 全ソケット

Windows での同等コマンド

# cmd.exe
ipconfig                     # 全情報
ipconfig /all                # 詳細(DNS / DHCP も)

# PowerShell
Get-NetIPAddress
Get-NetIPAddress -AddressFamily IPv4
Get-NetIPConfiguration       # 包括的に

# 特定アダプタ
Get-NetIPAddress -InterfaceAlias &quot;イーサネット&quot;

# 経路
Get-NetRoute -DestinationPrefix &quot;0.0.0.0/0&quot;
route print                  # 旧

macOS での同等

# macOS は ifconfig がまだ標準
ifconfig
ifconfig en0                 # Wi-Fi
ifconfig en1                 # 有線(モデルによる)

# 簡潔
ipconfig getifaddr en0       # IPv4 だけ
networksetup -getinfo Wi-Fi

# ip コマンドは未搭載(brew install iproute2mac で代替可)

典型的なトラブル切り分け

  1. ip a で IP が割り当たっているか確認
  2. ip route でデフォルトゲートウェイがあるか
  3. ping -c 3 デフォルトGW で L2 疎通確認
  4. ping -c 3 8.8.8.8 で L3 (外向き) 疎通
  5. nslookup google.com で DNS 解決
  6. curl -v https://google.com で HTTPS / 証明書確認

FAQ

Q: ifconfig: command not found
A: 最近のディストリでは net-tools パッケージが既定で入りません。sudo apt install net-tools(Ubuntu)/ sudo dnf install net-tools(RHEL)でインストール、または ip コマンドに移行を推奨します。

Q: IP が DHCP で取得できているか確認したい
A: ip a の出力で dynamic という単語が IPv4 行に付いていれば DHCP 取得です。journalctl -u NetworkManager/var/log/syslog で取得ログも確認可能。

Q: 一時的に IP を変更したい
A: sudo ip addr add 192.168.1.20/24 dev eth0。再起動で消えます。永続化は /etc/netplan(Ubuntu)/ nmcli(RHEL)で。