2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Mac でデフォルト NIC のプライベート IP アドレス を調べる方法

Last updated at Posted at 2020-01-15

デフォルトの NIC を調べる

有線 LAN と無線を同時接続している時など、複数 NIC がある場合、まずはデフォルトの NIC の名前を特定する必要があります。

DEFAULT_INTERFACE=`route -n get default | grep 'interface' | awk '{print $2}'`
echo $DEFAULT_INTERFACE

NIC からプライベート IP アドレス を調べる

NIC 名がわかれば以下のコマンドで簡単に IP アドレスを調べられます。

DEFAULT_IP_ADDRESS=`ipconfig getifaddr $DEFAULT_INTERFACE`
echo $DEFAULT_IP_ADDRESS

まとめ

.zshrc とかに仕込んどくと便利かもしれません。

echo 'export DEFAULT_INTERFACE=`route -n get default | grep '"'"'interface'"'"' | awk '"'"'{print $2}'"'"'`' >> ~/.zshrc
echo 'export DEFAULT_IP_ADDRESS=`ipconfig getifaddr $DEFAULT_INTERFACE`' >> ~/.zshrc
2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?