0
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?

ifconfigでローカルアドレスを特定する

Last updated at Posted at 2025-09-30

概要

よく使うけど、いっつも調べているので備忘録的に

コマンド

ifconfig en0 | grep "inet " | grep -v inet6 | awk '{print $2}'

いっつも適当に使ってたから何やってるか調べた

ifconfigでネットワーク指定できるの知らなかった
正直これだけで、後のオプション要らないわ...

いつもはifconfig打った後にどこかなーって調べてた

ifconfig en0

inet から始まる文字列を探す

grep "inet "

inet6を-vオプションで除く

grep -v inet6

awk全然使ったことなかったけど、タブとか空白で分割、配列で持ってる?のを0〜n番目で指定してやれば該当の部分だけを取り出せる。

awk '{print $2}'

最終的に

192.168....

とかのローカルアドレスを特定できる。

まとめ

grepとか使いこなせるとかっこいいけど、そううまくいかないよねえ

追記

会社の人に教えてもらった。
便利そう。最近のlinuxにデフォで入ってるらしいから、こっち推奨
macに入れるの面倒なら、ifconfigって感じ

0
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
0
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?