profile image

L o a d i n g . . .

네트워크 인터페이스// 이름은 어디서 많이 들어봤는데 정확히 잘 모릅니다.

얼마 전에 회사에서 운영하는 서버에서 서버 인터페이스가 내려가는 일이 일어났었습니다.
관련해서 전문 부서에서 해결해주셨는데요, ifconfig 명령어 찾아보며 알아보긴 했지만, 인터페이스가 뭔지 개념도 잘 몰라 벙쪄있던 기억이 있습니다.

이 기회에 네트워크 인터페이스, ifconfig 명령어 관련해 관련 지식을 잘 정리해놓으려고 합니다.

네트워크 인터페이스란?

네트워크 인터페이스는 컴퓨터를 네트워크에 연결해주는 역할을 합니다.

os 커널 소프트웨어 side에서 일어나는 네트워킹을 실제 하드웨어 네트워크 장치와 이어준다고 합니다. (컴퓨터가 네트워크 장치와 연결되는 지점)

컴퓨터가 네트워크에 연결하여 통신하기 위해 사용되는 하드웨어 장치는 무엇이 있을까요?

네트워크 인터페이스 컨트롤러(Network Interface Controller)

네트워크 인터페이스 컨트롤러(network interface controller, NIC)는 컴퓨터를 네트워크에 연결하여 통신하기 위해 사용하는 하드웨어 장치이다. 네트워크 카드(network card), 랜 카드(문화어: 망카드, 망기판, LAN card), 물리 네트워크 인터페이스(physical network interface) 라고 하며, 네트워크 인터페이스 카드, 네트워크 어댑터, 네트워크 카드, 이더넷 카드 등으로도 불립니다.

OSI 계층 1(물리 계층)과 계층 2(데이터 링크 계층) 장치를 가지는데, MAC 주소를 사용하여 낮은 수준의 주소 할당 시스템을 제공하고 네트워크 매개체로 물리적인 접근을 가능하게 합니다. 사용자들이 케이블을 연결하거나 무선으로 연결하여 네트워크에 접속할 수 있습니다.
위키피디아 참고

it회사 기술 면접 준비할 때 많이 보았던, OSI 1계층 2계층, MAC 주소 모두 여기 쓰이네요.

예전에는 카드 형식으로 외부에서 컴퓨터에 꽂아 사용하기도 한 것 같은데, 요즘은 컴퓨터 메인 보드 안에 다 내장되어 있는 것 같습니다.(기본적으로 무선 와이파이 연결도 가능하고, 랜 케이블(LAN(local access network) cable) 포트도 있으니까요)

네트워크 인터페이스 컨트롤러(NIC)가 하는 일을 간단히 더 살펴보자면, 다음과 같습니다.

  1. 컴퓨터와 LAN 사이의 통신을 준비
  2. 전송될 데이터를 병렬에서 직렬로 변환. 데이트를 비트 스트림으로 전송(0 또는 1)
  3. 목적기 호스트의 NIC 는 전송된 데이터를 수신하고, CPU로 데이터를 전달하는 책임이 있음. (인터럽트를 통해 CPU에게 전송, 수신을 확인시켜준다.)
  4. 필터링 기능. 데이터 헤더에 담겨있는 MAC 주소와 실제 컴퓨터 MAC 주소 일치/불일치 여부 확인.(OSI 3계층에서는 IP주소, 4계층에서는 포트 정보를 일치 여부를 확인한다고 합니다.)

네트워크 인터페이스 2가지 타입

리눅스 시스템은 두 가지 타입으로 네트워크 인터페이스를 구별합니다.

  1. Pysical interface 물리 인터페이스
  2. Virtual interface 가상 인터페이스

Pysical interface 물리 인터페이스

컴퓨터에 연결된 실제 네트워크 하드웨어 장치를 의미합니다.

방금 살펴본 NIC (Network Interface Card), WNIC (Wireless Network Interface Card), 모뎀 등이 물리 네트워크 인터페이스로 인식됩니다.

실제로 컴퓨터 인터페이스 목록을 보면 eth0 을 볼 수 있는데요, eth0 은 이더넷 네트워크 카드를 의미하는 인터페이스 입니다.

즉, NIC 과 1:1 매핑되는 Interface를 물리 인터페이스로 이해하면 됩니다.

Virtual interface 가상 인터페이스

실제 네트워크 하드웨어 장치와 1:1 매핑되지 않으면 다 virtual interface라 할 수 있습니다.

Loopback, bridges, VLANs, tunnel interface 등등 다양한 종류의 virtual interface가 있습니다.

소프트웨어 상으로 정의된 네트워크를 이용하여 구현된 기술들이 많아지며(도커, 쿠버네티스 등등), 최근 다양하게 사용되고 있다고 합니다.

ifconfig 으로 나오는 정보 파헤치기

인터페이스가 뭔지 감을 잡았으니, ifconfig 명령어로 우리가 어떤 것을 할 수 있는지 알아보겠습니다.

ifconfig 명령어

ifconfig 명령어는 네트워크 인터페이스를 설정할 수 있도록 도와줍니다.

만약 네트워크 인터페이스가 셋 업되지 않으면, 커널 장치 드라이버와 네트워크는 서로 통신할 수 있는 방법이 없습니다. ifconfig 는 설정 파일을 읽어 인터페이스를 boot up 시키고 설정하는 중요한 역할을 합니다.

방금 언급한 설정 파일은 /etc/network/interfaces 파일 입니다.(리눅스 데비안 계열에서 쓰인다네요)
대부분의 네트워크 설정은 이 파일에 의해 설정됩니다. 네트워크 인터페이스에 정적/동적으로 ip 주소를 할당, 라우팅 설정(dns 서버) 등등을 할 수 있다고 합니다. 인터페이스 정보를 볼 수 있다고도 하네요.

ifconfig 명령 출력

인수가 없는 ifconfig 명령은 활성화된 인터페이스의 세부 사항을 표시합니다.

왼쪽에 인터페이스 이름, 오른쪽에 자세한 정보가 나옵니다.

$ ifconfig

docker0   Link encap:Ethernet  HWaddr 02:42:2d:66:fc:f1  
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:2dff:fe66:fcf1/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:152 (152.0 B)  TX bytes:258 (258.0 B)

eth0      Link encap:Ethernet  HWaddr 08:00:27:31:65:b5  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::3db9:eaaa:e0ae:6e09/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1089467 errors:0 dropped:0 overruns:0 frame:0
          TX packets:508121 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:903808796 (903.8 MB)  TX bytes:31099448 (31.0 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:9643 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9643 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:719527 (719.5 KB)  TX bytes:719527 (719.5 KB)

loopback 인터페이스는 자기 자신의 컴퓨터를 의미합니다. 단순히 우리에게 돌아오는 것이죠(loop back). 디버킹하거나 로컬로 돌아가는 서버에 연결할 때 잘 쓰입니다.

eth0 이더넷 네트워크 카드를 의미하는 물리 인터페이스. 네트워크에 있는 다른 컴퓨터와 통신, 인터넷 으로 통신을 위해 사용됩니다.

lo 가상 네트워크 인터페이스로, loopback 장치로 불립니다. 자기 자신의 컴퓨터를 의미합니다. 단순히 우리에게 돌아오는 것이죠(loop back). 디버깅하거나 로컬에서 돌아가는 서버에 연결할 때 잘 쓰입니다.

docker0 도커에 의해 생성된 가상 브리지 인터페이스입니다. 이 브리지는 도커 컨테이너가 서로 통신할 수 있게 하는 분리된 네트워크를 생성합니다. 도커 네트워크 관련해서 기회가 되면 다음에 다뤄보겠습니다.

wlan0 위 예제에는 없지만 wireless interface를 의미합니다.

ifconfig 명령 출력(자세히)

$ ifconfig

docker0   Link encap:Ethernet  HWaddr 02:42:2d:66:fc:f1  
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:2dff:fe66:fcf1/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:152 (152.0 B)  TX bytes:258 (258.0 B)

eth0      Link encap:Ethernet  HWaddr 08:00:27:31:65:b5  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::3db9:eaaa:e0ae:6e09/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1089467 errors:0 dropped:0 overruns:0 frame:0
          TX packets:508121 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:903808796 (903.8 MB)  TX bytes:31099448 (31.0 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:9643 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9643 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:719527 (719.5 KB)  TX bytes:719527 (719.5 KB)

Link encap shows how packets are encapsulated for transmission. Most interfaces wrap packets in Ethernet frames.

HWaddr is hardware address of the ethernet interface (also known as MAC address).

inet addr is IPv4 address assigned to the interface.

Bcast is broadcast address for the interface.

Mask is network mask for the interface.

inet6 addr is IPv6 address assigned to the interface.

Scope is scope of IPv6 address. It can be link-local or global. Link-local address is used in local area network and is not routable. Global address is routable.

UP indicates that kernel modules related to the interface have been loaded and interface is activated.

BROADCAST indicates that interface is configured to handle broadcast packets, which is required for obtaining IP address via DHCP.

RUNNING indicates that interface is ready to accept data.

MULTICAST indicates that interface supports multicasting.

MTU is maximum transmission unit. IP datagrams larger than MTU bytes will be fragmented into multiple Ethernet frames.

Metric determines the cost of using the interface. Interfaces with lower cost have higher priority.

interface stats
RX packets is a total number of packets received.

RX errors shows a total number of packets received with error. This includes too-long-frames errors, ring-buffer overflow errors, CRC errors, frame alignment errors, fifo overruns, and missed packets.

RX dropped is a number of dropped packets due to unintended VLAN tags or receiving IPv6 frames when interface is not configured for IPv6.

RX overruns is a number of received packets that experienced fifo overruns, caused by rate at which a buffer gets full and kernel isn’t able to empty it.

RX frame is a number of misaligned frames, i.e. frames with length not divisible by 8.

TX packets is total number of packets transmitted.

TX errors, TX dropped and TX overruns are similar to RX equivalents.

TX carriers is a number of packets that experienced loss of carriers. This usually happens when link is flapping.

TX collisions is a number of transmitted packets that experienced Ethernet collisions.

TX txqueuelen is length of transmission queue.

RX bytes is a total number of bytes received over interface.

TX bytes is a total number of bytes transmitted over interface.

(https://codewithyury.com/demystifying-ifconfig-and-network-interfaces-in-linux/)

개발에 필요한 ifconfig 명령어 (참고 사이트)

리눅스 네트워크 관리에 필요한 ifconfig 사용법 11가지

결론

ifconfig 명령어로 물리/가상 인터페이스 디테일한 정보들을 확인할 수 있습니다.

참고

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=stop2y&logNo=220062222926

https://unagi44.wordpress.com/2020/11/21/ict-%EA%B8%B0%EB%B3%B8%EC%A7%80%EC%8B%9D-nic-%EC%9D%B4%EB%9E%80-%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80/

https://www.baeldung.com/linux/network-interface-configure

https://codewithyury.com/demystifying-ifconfig-and-network-interfaces-in-linux/

https://linuxjourney.com/lesson/network-interfaces

https://developers.redhat.com/blog/2018/10/22/introduction-to-linux-interfaces-for-virtual-networking

복사했습니다!