2021. 12. 20. 15:49

network 설정(펌글)

OS : CentOS 7

 

 

nmcli d[evice] 명령을 사용하여 이더넷 장치명을 확인할 수 있습니다.

                                                                                                            
[root@localhost ~]# nmcli d
DEVICE    TYPE        STATE        CONNECTION
eth0      ethernet    disconnected --
lo        loopback    unmanaged    --
                                                                                                            
cs

 

eth0 에 대해 네트워크 설정을 하도록 하겠습니다.

 

 

 

첫번째 방법입니다. 다음 명령을 사용합니다.

                                                                                                            
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
                                                                                                       
cs

 

처음 명령을 실행하면 아래와 비슷한 default 설정을 볼 수 있습니다.

                                                                                                            
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=996b6722-4260-44bc-9311-7f9dedc333ea
DEVICE=eth0
ONBOOT=no
                                                                                                            
cs

 

유동 IP(DHCP)를 사용하는 경우,

아래와 같이 ONBOOT=no 를 ONBOOT=yes 로 수정합니다. (BOOTPROTO=dhcp 기본값 그대로 사용)

                                                                                                            
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=996b6722-4260-44bc-9311-7f9dedc333ea
DEVICE=eth0
ONBOOT=yes
                                                                                                            
cs

 

고정 IP(Static)를 사용하는 경우,

아래와 같이 수정 및 내용을 추가합니다.

BOOTPROTO=none 또는 BOOTPROTO=static 둘 중 어느 것을 사용하든 상관없으며,

PREFIX 값 또는 NETMASK 주소 둘 중 어느 것을 입력하든 역시 상관없습니다.

또 맨 밑의 사용할 DNS 서버 주소 또한 여기에 입력해도 되고 입력하지 않아도 당장은 상관없습니다.

(물론 여기에 입력하지 않으면 여기가 아닌 다른 곳에 입력을 해야합니다.)

                                                                                                            
TYPE=Ethernet
BOOTPROTO=none
#BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=996b6722-4260-44bc-9311-7f9dedc333ea
DEVICE=eth0
ONBOOT=yes
IPADDR=10.20.30.41
PREFIX=24
#NETMASK=255.255.255.0
GATEWAY=10.20.30.254
DNS1=168.126.63.1
DNS2=168.126.63.2
                                                                                                            
cs

 

 

 

 

두번째 방법입니다. 다음 명령을 사용합니다.

                                                                                                            
[root@localhost ~]# nmtui
                                                                                                            
cs

 

Edit a connection 을 선택합니다.

 

 

eth0 을 선택합니다.

 

 

유동 IP(DHCP)를 사용하는 경우,

Automatically connect 를 체크하고 OK 합니다.

(IPv4 CONFIGURATION <Automatic> 기본값 그대로 사용)

 

고정 IP(Static)를 사용하는 경우,

IPv4 CONFIGURATION 의 <Automatic>을 <Manual>로 변경하고,

바로 우측에 <Show> 를 눌러 수동 설정이 가능하도록 변경합니다.

이후, Addresses 와 Gateway 를 입력하고 Automatically connect 를 체크하고 OK 합니다.

 

 

 

 

세번째 방법입니다. nmcli c[onnection] m[odify] 명령을 이용합니다.

유동 IP(DHCP)를 사용하는 경우, (BOOTPROTO=dchp)

                                                                                                            
[root@localhost ~]# nmcli c m eth0 ipv4.method auto
                                                                                                            
cs

부팅 혹은 리부팅 시 eth0 이 자동으로 연결되도록 설정합니다. (ONBOOT=yes)

                                                                                                            
[root@localhost ~]# nmcli c m eth0 connection.autoconnect yes
                                                                                                            
cs

 

고정 IP(Static)를 사용하는 경우, (BOOTPROTO=none)

                                                                                                            
[root@localhost ~]# nmcli c m eth0 ipv4.method manual
                                                                                                            
cs

부팅 혹은 리부팅 시 eth0 이 자동으로 연결되도록 설정합니다. (ONBOOT=yes)

                                                                                                            
[root@localhost ~]# nmcli c m eth0 connection.autoconnect yes
                                                                                                            
cs

IP 주소를 설정합니다. (IPADDR=10.20.30.41 / PREFIX=24)

                                                                                                            
[root@localhost ~]# nmcli c m eth0 ipv4.addresses 10.20.30.41/24
                                                                                                           
cs

Gateway 주소를 설정합니다. (GATEWAY=10.20.30.254)

                                                                                                            
[root@localhost ~]# nmcli c m eth0 ipv4.gateway 10.20.30.254
                                                                                                            
cs

DNS 서버 주소를 설정합니다. (DNS1=168.126.63.1 / DNS2=168.126.63.2)

                                                                                                            
[root@localhost ~]# nmcli c m eth0 ipv4.dns "168.126.63.1 168.126.63.2"
                                                                                                           
cs

 

위의 내용을 아래와 같이 한번에 입력할 수도 있습니다.

                                                                                                            
[root@localhost ~]# nmcli c m eth0 ipv4.method manual connection.autoconnect yes ipv4.addresses 10.20.30.41/24 ipv4.gateway 10.20.30.254 ipv4.dns "168.126.63.1 168.126.63.2"
                                                                                                          
cs

 

 

 

이제 위에서 DNS 서버 주소를 입력하지 않은 경우, resolv.conf 에 DNS 서버 주소를 입력해줘야 합니다.

(추가했다면 바로 네트워크 서비스 재시작으로 넘어가셔도 좋습니다.)

                                                                                                            
[root@localhost ~]# vi /etc/resolv.conf
                                                                                                            
cs

 

사용할 DNS 서버 주소를 추가합니다.

                                                                                                            
nameserver 168.126.63.1
nameserver 168.126.63.2
                                                                                                            
cs

 

 

 

네트워크 서비스를 재시작합니다.

                                                                                                            
[root@localhost ~]# systemctl restart network
                                                                                                            
cs

 

 

 

확인

                                                                                                            
[root@localhost ~]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    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 qlen 1000
    link/ether 00:15:5d:1e:28:03 brd ff:ff:ff:ff:ff:ff
    inet 10.20.30.41/24 brd 10.20.30.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::71a6:e650:9b47:588e/64 scope link
       valid_lft forever preferred_lft forever
                                                                                      
cs

 

                                                                                                            
[root@localhost ~]# nmcli d
DEVICE    TYPE        STATE        CONNECTION
eth0      ethernet    connected  --
lo        loopback    unmanaged    --
                                                                                                            
cs

 

                                                                                                            
[root@localhost ~]# ping yahoo.co.kr
PING yahoo.co.kr (98.137.236.150) 56(84) bytes of data.
64 bytes from w2.src.vip.gq1.yahoo.com (98.137.236.150): icmp_seq=1 ttl=47 time=164 ms
64 bytes from w2.src.vip.gq1.yahoo.com (98.137.236.150): icmp_seq=2 ttl=47 time=164 ms
^C
--- yahoo.co.kr ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 164.414/164.435/164.457/0.406 ms
                                                                                                            
cs

 

 

- 원본

https://m.blog.naver.com/tequini/220977723865

Trackback 0 Comment 0