본문 바로가기

Linux/3) 리눅스 네트워크 관리자 과정

01_01 Network Configuration Administration - 네트워크 설정 파일

네트워크 설정 파일 종류

  • /etc/hosts 파일
  • /etc/host.conf 파일 (/etc/nsswitch.conf)
  • /etc/resolv.conf 파일
  • /etc/sysconfig/network 파일
  • /etc/sysconfig/network-scripts/ifcfg-eth0 파일

네트워크 설정 확인 명령어

  • ethtool 명령어
  • ifconfig 명령어
  • netstat -nr 명령어
  • /etc/resolv.conf 파일

1) /etc/hosts 파일

[root@server1 ~]# man hosts
NAME
       hosts - static table lookup for hostnames

SYNOPSIS
       /etc/hosts

DESCRIPTION
       This manual page describes the format of the /etc/hosts file.  This file is a
       simple text file that associates IP addresses with hostnames, one line per IP
       address.   For  each  host a single line should be present with the following
       information:

              IP_address canonical_hostname [aliases...]

       Fields of the entry are separated by any number of blanks and/or tab  charac‐
       ters.   Text from a "#" character until the end of the line is a comment, and
       is ignored.  Host names may contain only alphanumeric characters, minus signs
       ("-"),  and  periods (".").  They must begin with an alphabetic character and
       end with an  alphanumeric  character.   Optional  aliases  provide  for  name
       changes,  alternate  spellings,  shorter hostnames, or generic hostnames (for
       example, localhost).

: /etc/hosts 파일은 아이피(IP)와 호스트이름 (hostname) 또는 도메인 이름(Domain Name)을 맵핑(Mapping)하는 역할을 가짐

: 작은 네트워크에서는 DNS를 대신하도록 설정

: 자세한 내용은 "# man hosts" 메뉴얼 확인

 

# cat /etc/hosts          내용 확인

[root@server1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


#
# Server List
#
192.168.10.10	main.example.com 	main
192.168.10.20	server1.example.com	server1
192.168.10.30	server2.example.com	server2

 

∇ /etc/hosts 파일 성격에 대한 실습

# ping 192.168.10.10

# ping main.example.com

# ping main 

-> 다 같은 결과가 나옴

 

# telnet localhost

# ssh localhost

# ssh 127.0.0.1

-> 다 같은 결과가 나옴

 

2) /etc/host.conf 파일

[root@server1 ~]# man host.conf
NAME
       host.conf - resolver configuration file

DESCRIPTION
       The  file  /etc/host.conf  contains configuration information specific to the
       resolver library.  It should contain one configuration keyword per line, fol‐
       lowed  by  appropriate configuration information.  The following keywords are
       recognized:
       
       multi  Valid values are on and off.  If set to on, the resolver library  will
              return  all  valid addresses for a host that appears in the /etc/hosts
              file, instead of only the first.  This is on by default.   On  systems
              with  DNS,  hosts  files  are much smaller and the performance loss of
              multiple search is negligible. On sites with large hosts files,  turn‐
              ing it on may cause a substantial performance loss.

: 유효한 값은 on과 off로 on으로 설정하면, 라이브러리는 첫번째 대신 /etc/hosts 파일에 나타나는 호스트에 대해 유효한 모든 주소를 반환하고 기본적으로 켜져있음

: /etc/host.conf 파일은 이름 요청(도메인 요청, Naming Service Request)시 도메인/이름 검색 순서

: 자세한 내용은 " # man host.conf " 메뉴얼 확인

 

# cat /etc/host.conf    (# cat /etc/nsswitch.conf)

[root@server1 ~]# cat /etc/host.conf
multi on

(ㄱ) hosts : /etc/hosts 파일을 검색

(ㄴ) bind : DNS 서버에서 검색

 

예시)

http://www.naver.com (ㄱ) /etc/hosts -> (ㄴ) DNS (/etc/resolv.conf)
웹브라우저 이 부분을 먼저 물어보고 없으면 DNS 서버에 IP 정보를 물어봄

 

∇ /etc/host.conf 파일에 대한 실습

# ls -l /etc/host.conf

[root@server1 ~]# ls -l /etc/host.conf
-rw-r--r--. 1 root root 9  9월 10  2018 /etc/host.conf

 

# cat /etc/hosts

[root@server1 ~]# cat /etc/host.conf
multi on

 

# vi /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6


#
# Server List
#
192.168.10.10   main.example.com        main
192.168.10.20   server1.example.com     server1
192.168.10.30   server2.example.com     server2

 

# firefox www.naver.com

[root@server1 ~]# firefox www.naver.com &
[2] 3986
[1]   Done                    firefox http://www.naver.com

(ㄱ) /etc/hosts -> (ㄴ) /etc/resolv.conf 

/etc/hosts 파일에 없는 경우 DNS 서버에서 IP 정보를 가져옴

 

3) /etc/resolv.conf 파일

[root@server1 ~]# man resolv.conf
NAME
       resolv.conf - resolver configuration file

SYNOPSIS
       /etc/resolv.conf

DESCRIPTION
       The resolver is a set of routines in the C library that provide access to the
       Internet Domain Name System (DNS).  The resolver configuration file  contains
       information  that  is  read  by the resolver routines the first time they are
       invoked by a process.  The file is designed to be human readable and contains
       a  list of keywords with values that provide various types of resolver infor‐
       mation.  The configuration file is considered a trusted source of DNS  infor‐
       mation (e.g., DNSSEC AD-bit information will be returned unmodified from this
       source).

       If this file does not exist, only the name server on the local  machine  will
       be  queried;  the  domain name is determined from the hostname and the domain
       search path is constructed from the domain name.

: 이름 요청 할 DNS 서버를 지정할 때 사용하는 파일

: nameserver 지시자를 통해 설정하는 DNS 서버는 보통 3개까지 등록할 수 있음

 

# cat /etc/resolv.conf

[root@server1 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 168.126.63.1

 

- 대표적인 ISP DNS 주소 확인

(코넷) C:\> nslookup -q=NS kornet.net IP : 211.216.50.150, 211.216.50.160
(보라넷) C:\> nslookup -q=NS bora.net IP : 164.124.101.31, 203.248.240.31
(파워콤) C:\> nslookup -q=NS powercom.com IP : 216.69.185.26, 208.109.255.26
(하나로) C:\> nslookup -q=NS hanaro.net IP : 210.180.98.85, 221.139.108.194

- 외워두어야 할 DNS 주소

( KT ) 168.126.63.1
( LG ) 12.124.101.2
( Google ) 8.8.8.8

 

∇ /etc/resolv.conf 파일에 대한 실습

# nslookup www.google.com

Server: 168.126.63.1

Address: 172.217.175.36

[root@server1 ~]# nslookup www.google.com
Server:		168.126.63.1
Address:	168.126.63.1#53

Non-authoritative answer:
Name:	www.google.com
Address: 172.217.175.36
Name:	www.google.com
Address: 2404:6800:4004:81c::2004

 

# ping www.google.com  

[root@server1 ~]# ping www.google.com
PING www.google.com (172.217.175.36) 56(84) bytes of data.
64 bytes from nrt20s19-in-f4.1e100.net (172.217.175.36): icmp_seq=1 ttl=128 time=40.2 ms
64 bytes from nrt20s19-in-f4.1e100.net (172.217.175.36): icmp_seq=2 ttl=128 time=43.7 ms
64 bytes from nrt20s19-in-f4.1e100.net (172.217.175.36): icmp_seq=3 ttl=128 time=42.2 ms
64 bytes from nrt20s19-in-f4.1e100.net (172.217.175.36): icmp_seq=4 ttl=128 time=46.4 ms
64 bytes from nrt20s19-in-f4.1e100.net (172.217.175.36): icmp_seq=5 ttl=128 time=41.5 ms
^C
--- www.google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 12ms
rtt min/avg/max/mdev = 40.153/42.812/46.440/2.149 ms

 

# ping 172.217.175.36

[root@server1 ~]# ping 172.217.175.36
PING 172.217.175.36 (172.217.175.36) 56(84) bytes of data.
64 bytes from 172.217.175.36: icmp_seq=1 ttl=128 time=57.1 ms
64 bytes from 172.217.175.36: icmp_seq=2 ttl=128 time=41.4 ms
64 bytes from 172.217.175.36: icmp_seq=3 ttl=128 time=43.10 ms
64 bytes from 172.217.175.36: icmp_seq=4 ttl=128 time=48.3 ms
64 bytes from 172.217.175.36: icmp_seq=5 ttl=128 time=40.9 ms
^C
--- 172.217.175.36 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 12ms
rtt min/avg/max/mdev = 40.874/46.330/57.132/6.005 ms

 

4) /etc/sysconfig/network-scripts/ifcfg-ens33 파일

: /etc/sysconfig/network-scripts 디렉토리 안의 파일들은 ifcfg-* 이름 형식을 가짐

: 만약, ifcfg-ens33 이름이라면, ens33은 connection name 또는 profile name이라고 부름

 

# cd /etc/sysconfig/network-scripts

# ls

ifcfg-ens33

[root@server1 ~]# cd /etc/sysconfig/network-scripts/
[root@server1 /etc/sysconfig/network-scripts]# ls
ifcfg-ens33

 

# cat ifcfg-ens33

[root@server1 /etc/sysconfig/network-scripts]# cat ifcfg-ens33
TYPE=Ethernet			# 장치 연결 종류
PROXY_METHOD=none
BROWSER_ONLY=no					
BOOTPROTO=none			# none or static : 정적 IP, DHCP : 동적 IP
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33			# profile name == connection name
UUID=4b58f299-affe-4da6-bc67-78d42c20996f
DEVICE=ens33			# network adapter name (network adapter driver name)
ONBOOT=yes			# 부팅시에 활성화
IPADDR=192.168.10.20		# IP 주소
PREFIX=24			# Netmask (CIDR 표기법)
GATEWAY=192.168.10.2		# Gateway IP 주소
DNS1=168.126.63.1		# DNS 서버 IP 주소
IPV6_PRIVACY=no

 

 

※ [참고] /etc/sysconfig/network-scripts/ifcfg-* 파일 예제 

 고정 IP 설정 예 (Static IP 설정)
# cat /etc/sysconfig/network-scripts/ifcfg-ens33
-----------------------------------------------
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=b1c87085-589b-4947-88b6-2d717dfd963c
DEVICE=ens33
ONBOOT=yes
HWADDR=00:0C:29:AF:C4:C5
IPADDR=192.168.10.10
PREFIX=24
GATEWAY=192.168.10.2
DNS1=8.8.8.8
DOMAIN=example.com
IPV6_PRIVACY=no
-----------------------------------------------
 동적 IP 설정 예 (Dynamic IP 설정)
# cat /etc/sysconfig/network-scripts/ifcfg-ens33
-----------------------------------------------
HWADDR=00:0C:29:AF:C4:C5
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_PRIVACY=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=9df5663c-9db7-4cc3-9255-e401b2e55831
DEVICE=ens33
ONBOOT=yes
-----------------------------------------------




-> 동적 IP는 DHCP 서버에서 IP를 받음

 

5) 현재 설정 확인

- 현재 IP 설정 확인

# ip address

# ip addr

# ip a

 

# ip address     ( # ifconfig )    현재 IP 설정 확인

[root@server1 ~]# ip address
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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:3b:cb:fe brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.20/24 brd 192.168.10.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::ccd0:c90b:ad0b:fd9/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

 

# ip route    (# netstat -nr)

[root@server1 ~]# ip route
default via 192.168.10.2 dev ens33 proto static metric 100 
192.168.10.0/24 dev ens33 proto kernel scope link src 192.168.10.20 metric 100

: 라우팅 테이블 정보를 보여줌

: default via 192.168.10.2 는 기본 라이터를 나타냄   

 

※ [참고] NIC 카드 설정값 확인하는 명령어 (ethtool)

∇ ethtool

Display or change ethernet cart settings

: 전송속도 선택 (10M/ 100M/ 1000M)

: 전이중/ 반이중 방식 선택 (Full Duplex, Half Duplex)

 

- 사용방법 확인

# ethtool

# man ethtool

 

# ethtool ens33     연결관계 확인

[root@server1 ~]# ethtool ens33
Settings for ens33:
	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: d
	Wake-on: d
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes

: Link detected: yes - 스위치와 서버가 연결되어 있다는 것, no로 되어 잇다면 상대한테 받은 정보와 연결이 되어 있지 않은 것

 

6) 정리 - 네트워크 서렁 확인

① 물리적인 연결 확인

# ethtool eth0

② IP/ Netask 확인

# ip address (# ifconfig)

③ defaultrouter 확인

# netstat -nr

④ DNS 클라이언트 설정 확인

# cat /etc/resolv.conf