본문 바로가기

리눅스

리눅스에서 기본 게이트웨이를 사용하는 로컬 IP 주소를 추출하는 명령어

728x90

리눅스에서 기본 게이트웨이를 사용하는 로컬 IP 주소를 추출하는 명령어

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 65535
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        ether 02:42:ac:11:00:02  txqueuelen 0  (Ethernet)
        RX packets 3560  bytes 27641426 (27.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1906  bytes 133847 (133.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

ifconfig | grep "inet" | grep "broadcast" | awk '{print $2}'
$ ifconfig | grep "inet" | grep "broadcast" | awk '{print $2}'
172.17.0.2

 

ifconfig | awk '/inet .*broadcast/ {print $2}'
$ ifconfig | awk '/inet .*broadcast/ {print $2}'
172.17.0.2

 

ip addr show dev eth0 | awk '/inet / {print $2}' | cut -d '/' -f 1
$ ip addr show dev eth0 | awk '/inet / {print $2}' | cut -d '/' -f 1
172.17.0.2

 

728x90