본문 바로가기

기술 웹 사이트 링크/Linux

ip 명령어

ip link를 확인하다 잘 정리되어 있는 블로그가 있어 공유한다.

 

m.blog.naver.com/PostView.nhn?blogId=anysecure3&logNo=221608840938&proxyReferer=https:%2F%2Fwww.google.com%2F

 

[리눅스 명령어 / CentOS] 네트워크 인터페이스 관리하기

안녕하세요. 닷홈입니다!​이번 시간에는 네트워크 인터페이스 관리할 때 이용하는 명령어에 대해 알려드릴...

blog.naver.com

ifconfig

ifconfig 명령어 문법은 아래와 같습니다.

ifconfig [옵션] [인터페이스]

ifconfig 옵션은 아래와 같습니다.

<인터페이스> up

지정한 인터페이스 활성화

<인터페이스> down

지정한 인터페이스 비활성화

inet <주소>

지정한 인터페이스 IP 주소 설정

netmask <주소>

지정한 인터페이스 넷 마스크 설정

ifconfig # 네트워크 인터페이스 정보 확인

[root@dothome-world ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.227 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::2546:2957:53c:f3a3 prefixlen 64 scopeid 0x20<link> ether 08:00:27:77:e5:e8 txqueuelen 1000 (Ethernet) RX packets 3058 bytes 223814 (218.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1278 bytes 1351004 (1.2 MiB) 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 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 76 bytes 8096 (7.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 76 bytes 8096 (7.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifconfig eth0 # eth0 의 네트워크 인터페이스 정보 확인

[root@dothome-world ~]# ifconfig eth0 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.227 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::2546:2957:53c:f3a3 prefixlen 64 scopeid 0x20<link> ether 08:00:27:77:e5:e8 txqueuelen 1000 (Ethernet) RX packets 3095 bytes 226822 (221.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1296 bytes 1354736 (1.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifconfig eth0 down # eth0 네트워크 인터페이스 비활성화

[root@dothome-world ~]# ifconfig eth0 down [root@dothome-world ~]# ifconfig lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 76 bytes 8096 (7.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 76 bytes 8096 (7.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifconfig eth0 up # eth0 네트워크 인터페이스 활성화

[root@dothome-world ~]# ifconfig eth0 up [root@dothome-world ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.227 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::2546:2957:53c:f3a3 prefixlen 64 scopeid 0x20<link> ether 08:00:27:77:e5:e8 txqueuelen 1000 (Ethernet) RX packets 3095 bytes 226822 (221.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1296 bytes 1354736 (1.2 MiB) 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 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 76 bytes 8096 (7.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 76 bytes 8096 (7.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifconfig eth0 inet 192.168.0.228 netmask 255.255.255.0 # eth0 인터페이스 IP 및 넷 마스크 설정

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.228 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::2546:2957:53c:f3a3 prefixlen 64 scopeid 0x20<link> ether 08:00:27:77:e5:e8 txqueuelen 1000 (Ethernet) RX packets 3123 bytes 230387 (224.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1320 bytes 1357640 (1.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifconfig 명령어로 IP를 설정할 경우 재부팅하면 설정 전으로 되돌아갑니다.

만약에 영구적으로 설정을 원하시면 /etc/sysconfig/network-scripts/ifcfg-eth0 파일에서 설정을 해줘야 합니다.


ip

ip 명령어의 사용 방법은 아래와 같습니다.

ip [옵션] [오브젝트] [명령 옵션]

ip 명령어의 옵션은 아래와 같습니다.

addr

IP 주소에 관한 정보를 수정하거나 출력

link

네트워크 인터페이스의 상태를 관리하거나 출력

route

라우팅 테이블을 변경하거나 출력

ip 명령어의 명령 옵션은 아래와 같습니다.

add

addr add : IP 주소 추가

route add : 라우팅 테이블 추가

del

addr del : IP 주소 삭제

route del : 라우팅 테이블 삭제

set

link set : 지정한 네트워크 인터페이스 상태 변경

ip addr # 네트워크 인터페이스 정보 확인

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:77:e5:e8 brd ff:ff:ff:ff:ff:ff inet 192.168.0.227/24 brd 192.168.0.255 scope global noprefixroute dynamic eth0 valid_lft 6774sec preferred_lft 6774sec

ip link # 네트워크 인터페이스 연결 여부 확인

[root@dothome-world ~]# ip link 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:77:e5:e8 brd ff:ff:ff:ff:ff:ff

ip route # 라우팅 테이블 확인

[root@dothome-world ~]# ip route default via 192.168.0.1 dev eth0 proto dhcp metric 100 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.227 metric 100

ip addr add 192.168.0.234 dev eth0 # eth0 인터페이스에 관하여 IP 추가

[root@dothome-world ~]# ip addr add 192.168.0.234 dev eth0 [root@dothome-world ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:77:e5:e8 brd ff:ff:ff:ff:ff:ff inet 192.168.0.227/24 brd 192.168.0.255 scope global noprefixroute dynamic eth0 valid_lft 6389sec preferred_lft 6389sec inet 192.168.0.234/32 scope global eth0 valid_lft forever preferred_lft forever

ip addr del 192.168.0.234 dev eth0 # eth0 인터페이스에 관하여 IP 제거

[root@dothome-world ~]# ip addr del 192.168.0.234 dev eth0 [root@dothome-world ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:77:e5:e8 brd ff:ff:ff:ff:ff:ff inet 192.168.0.227/24 brd 192.168.0.255 scope global noprefixroute dynamic eth0 valid_lft 6318sec preferred_lft 6318sec

ip route add 192.168.0.0/24 via 192.168.0.1 # eth0 인터페이스에 관하여 라우팅 테이블 추가

[root@dothome-world ~]# ip route add 192.168.0.0/24 via 192.168.0.1 [root@dothome-world ~]# ip route default via 192.168.0.1 dev eth0 proto dhcp metric 100 192.168.0.0/24 via 192.168.0.1 dev eth0 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.227 metric 100

ip route del 192.168.0.0/24 via 192.168.0.1 # eth0 인터페이스에 관하여 라우팅 테이블 제거

[root@dothome-world ~]# ip route del 192.168.0.0/24 via 192.168.0.1 [root@dothome-world ~]# ip route default via 192.168.0.1 dev eth0 proto dhcp metric 100 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.227 metric 100

ip link set eth0 down # eth0 인터페이스 비활성화

[root@dothome-world ~]# ip link set eth0 down [root@dothome-world ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:77:e5:e8 brd ff:ff:ff:ff:ff:ff

ip link set eth0 up # eth0 인터페이스 활성화

[root@dothome-world ~]# ip link set eth0 up [root@dothome-world ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 08:00:27:77:e5:e8 brd ff:ff:ff:ff:ff:ff inet 192.168.0.227/24 brd 192.168.0.255 scope global noprefixroute dynamic eth0 valid_lft 7199sec preferred_lft 7199sec

ifconfig 명령어와 동일하게 ip 명령어로 IP 설정을 할 경우 재부팅 후에는 설정 전으로 되돌아갑니다.

만약에 영구적으로 설정을 원하시면 /etc/sysconfig/network-scripts/ifcfg-eth0 파일에서 설정을 해줘야 합니다.


ifup & ifdown

ifup 명령어와 ifdown 명령어 사용 방법은 아래와 같습니다.

ifup [인터페이스명]

ifdown [인터페이스명]

ifup eth0​ # eth0 인터페이스 활성화

[root@dothome-world ~]# ifup eth0 [root@dothome-world ~]# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.0.227 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::2546:2957:53c:f3a3 prefixlen 64 scopeid 0x20<link> ether 08:00:27:77:e5:e8 txqueuelen 1000 (Ethernet) RX packets 4253 bytes 322013 (314.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1655 bytes 1405112 (1.3 MiB) 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 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 192 bytes 20076 (19.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 192 bytes 20076 (19.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifdown eth0 # eth0 인터페이스 비활성화

[root@dothome-world ~]# ifdown eth0 [root@dothome-world ~]# ifconfig lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 192 bytes 20076 (19.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 192 bytes 20076 (19.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

ifdown 명령어는 사용하기 전에 비활성화할 네트워크 인터페이스가 맞는지 정확하게 확인 후 진행해 주셔야 합니다.


ethtool

ethtool 사용방법은 아래와 같습니다.

ethtool [옵션] [인터페이스명] [파라미터]

ethtool 옵션은 아래와 같습니다.

-s

인터페이스 설정

ethtool 파라미터 값은 아래와 같습니다.

speed 10|100|1000

네트워크 인터페이스 속도 변경

duplex half|full

네트워크 인터페이스 전송 모드

autoneg on|off

네트워크 인터페이스 Auto-Negotiation 기능 on/off 여부

ethtool eth0 # eth0 네트워크 인터페이스 설정 확인

Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: umbg Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes

ethtool -s eth0 speed 100 duplex half autoneg off

# eth0 인터페이스에 관하여 속도, 통신 방식, Auto-Negotiation 기능 설정

[root@dothome-world ~]# ethtool -s eth0 speed 100 duplex half autoneg off [root@dothome-world ~]# ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: Not reported Advertised pause frame use: No Advertised auto-negotiation: No Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: off MDI-X: off (auto) Supports Wake-on: umbg Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes

ethtool -s eth0 speed 1000 duplex full

# eth0 인터페이스에 관하여 속도, 통신 방식 설정

[root@dothome-world ~]# ethtool -s eth0 speed 1000 duplex full [root@dothome-world ~]# ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: umbg Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes

해당 명령어는 네트워크 인터페이스 최적화나 네트워크 인터페이스 테스트 용도로도 많이 이용하는 명령어입니다.

 

'기술 웹 사이트 링크 > Linux' 카테고리의 다른 글

Systemctl/journalctl 명령어  (0) 2021.04.02