-
네트워크 설정linux/centOS 2018. 7. 11. 11:13
☆ 네트워크 설정 파일
■ 네트워크 설정 파일 종류
/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 파일
/etc/hosts 파일은 아이피(IP)와 호스트 이름(hostname) 또는 도메인 이름(Domain Name)을 맵핑(Mapping)하는 역할을 가진다. 작은 네트워크에서는 DNS을 대신하도록 설정할 수도 있다.
자세한 내용은 "# man hosts" 매뉴얼을 확인한다.
# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
172.16.9.2XX linux2XX.example.com linux2XX -> 어떤걸 쓰던지 ip주소로 실행됨.
#
# (1) Linux Server List
#
172.16.9.200 linux200.example.com linux200
172.16.9.201 linux201.example.com linux201
172.16.9.202 linux202.example.com linux202
(2) /etc/host.conf 파일
/etc/host.conf 파일은 이름 요청(도메인 요청, Naming Service Request)시 도메인/이름 검색 순서를 나타낸다.
자세한 내용은 "# man host.conf" 매뉴얼을 확인한다.
# cat /etc/host.conf (# cat /etc/nsswitch.conf)
order hosts,bind --> host.conf에 등록되어 있으면 거기서 ip주소를 찾고 만약 host.conf
파일이 없다면 bind서버(dns서버)에서 ip주소를 찾는다
-> (ㄱ) hosts : /etc/hosts 파일을 검색
-> (ㄴ) bind : DNS 서버에서 검색
웹브라우저
(예) http://www.daum.net -> (ㄱ) /etc/hosts -> (ㄴ) DNS(/etc/resolv.conf)
(3) /etc/resolv.conf 파일
이름 요청을 할 DNS 서버를 지정할 때 사용하는 파일이다.
# cat /etc/resolv.conf
search example.com --> search 뒤에 쓰인 도메인은 생략하고 사용 가능하다.
ex) nslookup www 만 써도 nslookup www.example.com과 같다.
nameserver 168.126.63.1 /* 168.126.63.1 : kns.kornet.net */
nameserver 168.126.63.2 /* 168.126.63.2 : kns.kornet.net */
-> 대표적인 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)
(4) /etc/sysconfig/network 파일
시스템의 호스트이름/기본라우터 정보를 지정할 때 사용하는 파일이다.
# cd /etc/sysconfig
# ls
apm-scripts/ grub lm_sensors readonly-root
apmd hidd mkinitrd/ rhn/
atd hsqldb modules/ samba
auditd httpd named saslauthd
authconfig hwconf named.rpmnew selinux@
autofs i18n netconsole sendmail
bluetooth i18n.old network smartmontools
cbq/ init network-scripts/ spamassassin
clock ip6tables-config networking/ squid
conman iptables-config nfs syslog
console/ irda nspluginwrapper system-config-securitylevel
cpuspeed irqbalance ntpd system-config-users
crond kdump pand tux
desktop kernel pm-action udev-stw
dovecot keyboard prelink vncservers
dund krb524 raid-check wpa_supplicant
firstboot kudzu rawdevices xinetd
# cat network
NETWORKING=yes /* NIC 카드 사용 여부 */
NETWORKING_IPV6=no /* IPv6 사용 여부 */
HOSTNAME=linux249.example.com /* 호스트 이름 */
GATEWAY=172.16.0.1 /* Gateway IP 주소(EX: defaultrouter) */
(5) /etc/sysconfig/network-scripts/ifcfg-eth0 파일
NIC(EX: eth0)의 IP 설정을 할 때 사용하는 파일이다.
# cd /etc/sysconfig/network-scripts
# ls
ifcfg-eth0 ifdown-ppp* ifup-ipsec* ifup-sl*
ifcfg-lo ifdown-routes* ifup-ipv6* ifup-tunnel*
ifdown@ ifdown-sit* ifup-ipx* ifup-wireless*
ifdown-bnep* ifdown-sl* ifup-isdn@ init.ipv6-global*
ifdown-eth* ifdown-tunnel* ifup-plip* net.hotplug*
ifdown-ippp* ifup@ ifup-plusb* network-functions
ifdown-ipsec* ifup-aliases* ifup-post* network-functions-ipv6
ifdown-ipv6* ifup-bnep* ifup-ppp*
ifdown-isdn@ ifup-eth* ifup-routes*
ifdown-post* ifup-ippp* ifup-sit*
# cat ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0 /* NIC Device Name */
BOOTPROTO=static /* static or none : 고정 IP 설정 */
BROADCAST=172.16.255.255 /* Broadcast Address */
HWADDR=00:0C:29:B6:F4:26/* MAC Address */IPADDR=172.16.9.249 /* IP Address */
NETMASK=255.255.0.0 /* Netmask */
NETWORK=172.16.0.0 /* Network Number */
ONBOOT=yes /* 부팅시에 NIC(EX: eth0) 활성화 여부 */
or
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
BROADCAST=172.16.10.255
HWADDR=00:0c:29:18:9e:b2IPADDR=172.16.10.249
NETMASK=255.255.255.0
NETWORK=172.16.10.0
ONBOOT=yes
GATEWAY=172.16.10.1
TYPE=Ethernet
[참고] /etc/sysconfig/networking 디렉토리
# cd /etc/sysconfig/networking
# ls
devices/ profiles/
# cd devices
# ls
#
-> 내용이 없다. (device 디렉토리 내에는 백업본이 들어있기 때문에 있는걸 지워도 상관없다. 없는게 정상이다.)
# cd ../profiles
# ls
default/
# cd default
# ls
#
-> 내용이 없다. (초기에는 아무 내용이 없기 때문에 디렉토리내의 파일을 지워도 무방하다.)
[참고] /etc/sysconfig/network-scripts/ifcfg-eth<N> 파일 예제
■ 고정 IP 설정 예(Static IP 설정) /* IP를 고정을 할당 */
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
-----------------------------------------------
DEVICE=eth0
BOOTPROTO=none or BOOTPROTO=static
ONBOOT=yes
NETWORK=172.16.0.0
NETMASK=255.255.0.0
IPADDR=172.16.9.249
USERCTL=no
-----------------------------------------------
■ 동적 IP 설정 예(Dynamic IP 설정) /* DHCP 서버로 부터 IP 할당 */
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
-----------------------------------------------
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
-----------------------------------------------
(6) 현재 설정 확인
(현재 IP 설정 확인)
# ifconfig /* 활성화(Activate) 된 인터페이스에 대한서만 정보 확인 */
# ifconfig -a /* 활성화(Activate) + 비활성화(Deactivate) 된 인터페이스 정보 확인 */
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:F4:26
inet addr:172.16.9.249 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feb6:f426/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:123511 errors:0 dropped:0 overruns:0 frame:0
TX packets:2339 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16233959 (15.4 MiB) TX bytes:196066 (191.4 KiB)
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:16436 Metric:1
RX packets:3277 errors:0 dropped:0 overruns:0 frame:0
TX packets:3277 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3084485 (2.9 MiB) TX bytes:3084485 (2.9 MiB)
-> 현재 활성화된(Active) NIC 설정을 보여준다.
# ifconfig –a
eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:F4:26
inet addr:172.16.9.249 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feb6:f426/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:124123 errors:0 dropped:0 overruns:0 frame:0
TX packets:2339 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16286941 (15.5 MiB) TX bytes:196066 (191.4 KiB)
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:16436 Metric:1
RX packets:3277 errors:0 dropped:0 overruns:0 frame:0
TX packets:3277 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3084485 (2.9 MiB) TX bytes:3084485 (2.9 MiB)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
-> 모든 NIC의 상태 정보(활성화된 NIC + 비활성화된 NIC)를 보여준다.
# netstat –nr /* -n : numeric, -r : routing table */
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 172.16.0.1 0.0.0.0 UG 0 0 0 eth0
-> 라우팅 테이블 정보를 보여준다.
-> 172.16.0.1 아이피는 기본 라우터를 나타낸다.
# cat /etc/resolv.conf
search example.com
nameserver 168.126.63.1 /* kns.kornet.net : 168.126.63.1 */
nameserver 168.126.63.2
[참고] NIC카드 설정값 확인하는 명령어(ethtool)
■ ethtool
Display or change ethernet card settings
-> 전송속도 선택(10M/100M/1000M)
-> 전이중/반이중 방식 선택(Full Duplex, Half Duplex)
-> (사용방법 확인)
# ethtool
# man ethtool
# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 1000baseT/Full
Supports auto-negotiation: No
Advertised link modes: Not reported
Advertised auto-negotiation: No
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: off
Link detected: yes
or
Settings for eth0:
Current message level: 0x00000007 (7)
Link detected: yes
or
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
Link detected: yes
(정리) 네트워크 설정 확인
(ㄱ) 물리적인 연결 확인
# ethtool eth0
(ㄴ) IP 확인
# ifconfig
(ㄷ) defaultrouter 확인
# netstat –nr
(ㄹ) DNS 클라이언트 설정 확인
# cat /etc/resolv.conf (# cat /etc/host.conf, /etc/nsswitch.conf)
☆ 네트워크 설정 툴 종류
■ 네트워크 설정 툴
# export LANG=en_US.UTF-8 (# export LANG=C)
(TUI) # system-config-network-tui (# setup)
(GUI) # system-config-network-gui (# neat)
# service network restart
[EX] 네트워크 설정 툴에 대한 실습
① 툴 종류 확인
# yum list | grep system-config
system-config-date.noarch 1.8.12-5.el5.centos installed
system-config-display.noarch 1.0.48-4.el5 installed
system-config-httpd.noarch 5:1.3.3.3-1.el5 installed
system-config-kdump.noarch 1.0.14-5.el5_9 installed
system-config-keyboard.noarch 1.2.11-1.el5 installed
system-config-language.noarch 1.1.18-3.el5 installed
system-config-lvm.noarch 1.1.5-13.el5 installed
system-config-netboot.noarch 0.1.45.1-5.el5 installed
system-config-netboot-cmd.noarch 0.1.45.1-5.el5 installed
system-config-network.noarch 1.3.99.21-1.el5 installed
system-config-network-tui.noarch 1.3.99.21-1.el5 installed
system-config-nfs.noarch 1.3.23-2.el5 installed
system-config-printer.x86_64 0.7.32.10-3.el5 installed
system-config-printer-libs.x86_64 0.7.32.10-3.el5 installed
system-config-rootpassword.noarch 1.1.9.1-1 installed
system-config-samba.noarch 1.2.41-5.el5 installed
system-config-securitylevel.x86_64 1.6.29.1-6.el5 installed
system-config-securitylevel-tui.x86_64 1.6.29.1-6.el5 installed
system-config-services.noarch 0.9.4-5.el5 installed
system-config-soundcard.noarch 2.0.6-1.el5 installed
system-config-users.noarch 1.2.51-7.el5 installed
system-config-audit.x86_64 0.4.10-7.el5 base
system-config-bind.noarch 4.0.3-6.el5.centos base
system-config-boot.x86_64 0.2.13-1.el5 base
system-config-cluster.noarch 1.0.57-16 base
system-config-kickstart.noarch 2.6.19.9-2.el5 base
[참고] redhat-config-* && system-config-*
RHEL 3.X : redhat-config-* (CentOS 3.X)
RHEL 4.X : system-config-* (CentOS 4.X)
# system-config-[TAB][TAB]
system-config-authentication system-config-nfs
system-config-date system-config-packages
system-config-display system-config-printer
system-config-httpd system-config-rootpassword
system-config-kdump system-config-samba
system-config-keyboard system-config-securitylevel
system-config-language system-config-securitylevel-tui
system-config-lvm system-config-services
system-config-network system-config-soundcard
system-config-network-cmd system-config-time
system-config-network-gui system-config-users
system-config-network-tui
② IP 변경 설정
■ IP 변경 (172.16.9.2XX -> 172.16.9.1XX)
# export LANG=C (# export LANG=en_US.UTF-8)
# system-config-network-tui
-> "Edit Devices"
-> "eth0 (eth0) - Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]"
-------------------------------------------
Name eth0
Device eth0
Use DHCP [ ]
Static IP 172.16.9.1XX /* (EX) 172.16.9.202 -> 172.16.9.102 */
Netmask 255.255.0.0
Default gateway IP 172.16.0.1
-------------------------------------------
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
BROADCAST=172.16.255.255
HWADDR=00:0c:29:b6:f4:26
IPADDR=172.16.9.1XX
NETMASK=255.255.0.0
NETWORK=172.16.0.0
ONBOOT=yes
GATEWAY=172.16.0.1
TYPE=Ethernet
# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:F4:26
inet addr:172.16.9.2XX Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feb6:f426/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:133978 errors:0 dropped:0 overruns:0 frame:0
TX packets:2344 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:17235237 (16.4 MiB) TX bytes:196336 (191.7 KiB)
# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
# ifconfig eth0
-> IP 설정 확인
③ IP 설정 복원
■ IP 변경 (172.16.9.1XX -> 172.16.9.2XX)
# system-config-network-gui &
-------------------------------------------
Address 172.16.9.2XX /* 172.16.9.102 -> 172.16.9.202 */
Subnet Mast 255.255.0.0
Default gateway Address 172.16.0.1
-------------------------------------------
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
BROADCAST=172.16.255.255
HWADDR=00:0c:29:b6:f4:26
IPADDR=172.16.9.2XX
NETMASK=255.255.0.0
NETWORK=172.16.0.0
ONBOOT=yes
GATEWAY=172.16.0.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:B6:F4:26
inet addr:172.16.9.1XX Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feb6:f426/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:140660 errors:0 dropped:0 overruns:0 frame:0
TX packets:2379 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:17903781 (17.0 MiB) TX bytes:202318 (197.5 KiB)
# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
# ifconfig eth0
-> IP 설정 확인
■ Network 설정 툴의 종류
(GUI) # system-config-network-gui (# neat)
(TUI) # system-config-network-tui (# setup)
■ IP 설정/변경 방법
- "네트워크 설정 툴" 사용하는 경우
# system-config-network-tui
# service network restart
- "직접 설정"하는 경우
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
# service network restart