클라우드 네이티브 애플리케이션 부트캠프 알림

티스토리 뷰

ip보기, ipv6 주소로 ping하기

ip보는 명령은 'ip a'입니다.

ipv6 주소는 fe80으로 항상 시작합니다.

ipv4 주소는 ping 명령어를 사용하고, ipv6는 ping6명령을 사용합니다.

아래 예제와 같이 'ping6 <ipv6주소>%<network interface명>'형식으로 ping할 수 있습니다.

예) ping6 fe80::404:bdff:fe84:bead%eth0

[root@bastion ~]# ip a
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 mq state UP group default qlen 1000
    link/ether 06:04:bd:84:be:ad brd ff:ff:ff:ff:ff:ff
    inet 10.178.41.148/26 brd 10.178.41.191 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::404:bdff:fe84:bead/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 06:2f:5e:b0:8d:90 brd ff:ff:ff:ff:ff:ff
    inet 169.56.96.107/28 brd 169.56.96.111 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::42f:5eff:feb0:8d90/64 scope link
       valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:98:11:a2:ac brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:98ff:fe11:a2ac/64 scope link
       valid_lft forever preferred_lft forever
[root@bastion ~]# ping6 fe80::404:bdff:fe84:bead%eth0
PING fe80::404:bdff:fe84:bead%eth0(fe80::404:bdff:fe84:bead%eth0) 56 data bytes
64 bytes from fe80::404:bdff:fe84:bead%eth0: icmp_seq=1 ttl=64 time=0.022 ms
64 bytes from fe80::404:bdff:fe84:bead%eth0: icmp_seq=2 ttl=64 time=0.044 ms

 

network 상태 보기

일반적으로 많이 사용하는 netstat명령 또는 ss라는 명령을 이용합니다.

아래 ss옵션은 udp나 tcp로 listen하고 있는 network 주소와 port를 리턴하라는 의미입니다.

netstat도 비슷한 옵션으로 동일한 결과를 얻을 수 있습니다.

[root@bastion ~]# netstat -lut
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 bastion.ibm.cloud:smtp  0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:https           0.0.0.0:*               LISTEN

 

ip routing 상태 보기

'ip r'이라는 명령으로 확인합니다.

[root@bastion ~]# ip r
default via 169.56.96.97 dev eth1
10.0.0.0/8 via 10.178.41.129 dev eth0
10.178.41.128/26 dev eth0 proto kernel scope link src 10.178.41.148
161.26.0.0/16 via 10.178.41.129 dev eth0
166.8.0.0/14 via 10.178.41.129 dev eth0
169.56.96.96/28 dev eth1 proto kernel scope link src 169.56.96.107
169.254.0.0/16 dev eth0 scope link metric 1002
169.254.0.0/16 dev eth1 scope link metric 1003
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1

 

DNS서버 보기

/etc/resolv.conf파일을 보면 됩니다.

[root@bastion ~]# cat /etc/resolv.conf
; Created by cloud-init on instance boot automatically, do not edit.
;
nameserver 10.0.80.11
nameserver 10.0.80.12

 

도메인까지 경로 보기

'tracepath <도메인명>'으로 확인합니다.

❯ docker run -it centos sh
sh-4.4#
sh-4.4# tracepath www.daum.net
 1?: [LOCALHOST]                      pmtu 1500
 1:  _gateway                                              0.050ms
 1:  _gateway                                              0.094ms
 2:  211.231.99.17                                         0.515ms pmtu 1452
 2:  172.30.1.254                                          2.287ms asymm 28
 3:  211.250.162.1                                         4.693ms asymm 28
 4:  125.141.249.142                                       5.943ms asymm 28
 5:  no reply
 6:  no reply
 7:  no reply
 8:  218.145.42.158                                       17.637ms asymm 28
 9:  no reply
10:  no reply
11:  no reply
12:  211.231.99.17                                         9.661ms reached
     Resume: pmtu 1452 hops 12 back 28

 

nmcli: Network Manager CLI

network설정은 /etc/sysconfig/network-script디렉토리의 'ifcfg-'로 시작하는 파일에서 합니다.

nmcli는 이 설정을 보다 손쉽게 하고 network 상태 정보를 제공하는 cli프로그램입니다.

먼저 NetworkManager를 시작합니다.

[root@bastion network-scripts]# systemctl status NetworkManager.service
● NetworkManager.service - Network Manager
   Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:NetworkManager(8)

Jun 03 14:00:24 bastion.ibm.cloud systemd[1]: Network Manager is not active.
[root@bastion network-scripts]# systemctl start NetworkManager.service
[root@bastion network-scripts]# nmcli
docker0: unmanaged
        "docker0"
        bridge, 02:42:98:11:A2:AC, sw, mtu 1500

eth0: unmanaged
        "eth0"
        ethernet (vif), 06:04:BD:84:BE:AD, hw, mtu 1500

eth1: unmanaged
        "eth1"
        ethernet (vif), 06:2F:5E:B0:8D:90, hw, mtu 1500

lo: unmanaged
        "lo"
        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

Use "nmcli device show" to get complete information about known devices and
"nmcli connection show" to get an overview on active connection profiles.

Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.

위 결과 메시지에 나와 있는 것처럼 'nmcli device show'명령으로 network device정보를 볼 수 있습니다.

그리고 'nmcli connection show'명령으로 활성화된 네트워크연결 프로파일 정보도 볼 수 있습니다.

[root@infra network-scripts]# nmcli d
DEVICE        TYPE      STATE      CONNECTION
ens192        ethernet  connected  ens192
cni-podman0   bridge    connected  cni-podman0
veth2820f5a1  ethernet  unmanaged  --
lo            loopback  unmanaged  --
[root@infra network-scripts]# nmcli d show ens192
GENERAL.DEVICE:                         ens192
GENERAL.TYPE:                           ethernet
GENERAL.HWADDR:                         00:50:56:00:00:98
GENERAL.MTU:                            1500
GENERAL.STATE:                          100 (connected)
GENERAL.CONNECTION:                     ens192
GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/1
WIRED-PROPERTIES.CARRIER:               on
IP4.ADDRESS[1]:                         10.178.41.165/26
IP4.GATEWAY:                            10.178.41.148
IP4.ROUTE[1]:                           dst = 0.0.0.0/0, nh = 10.178.41.148, mt = 100
IP4.ROUTE[2]:                           dst = 10.178.41.128/26, nh = 0.0.0.0, mt = 100
IP4.DNS[1]:                             10.178.41.148
IP4.DOMAIN[1]:                          cp.kubepia.net
IP6.ADDRESS[1]:                         fe80::dec4:874:4115:6b62/64
IP6.GATEWAY:                            --
IP6.ROUTE[1]:                           dst = fe80::/64, nh = ::, mt = 100
IP6.ROUTE[2]:                           dst = ff00::/8, nh = ::, mt = 256, table=255
[root@infra network-scripts]# nmcli c show
NAME         UUID                                  TYPE      DEVICE
ens192       daa5c8b3-f710-4a83-adcc-e3f514fbfcff  ethernet  ens192
cni-podman0  312be523-7039-40dc-b41b-3d4a2d4e342b  bridge    cni-podman0
[root@infra network-scripts]# nmcli c show ens192
connection.id:                          ens192
connection.uuid:                        daa5c8b3-f710-4a83-adcc-e3f514fbfcff
connection.stable-id:                   --
connection.type:                        802-3-ethernet
connection.interface-name:              ens192
connection.autoconnect:                 yes

nmcli명령으로 네트워크 설정을 바꿔도 되고, ifcfg-* 파일을 수정해도 됩니다.

ifcfg-*파일을 직접 변경한 경우는 아래와 같이 reload를 해줘야 합니다.

centos8부터는 'systemctl restart network'은 더 이상 지원 안하고 'nmcli con reload'를 사용해야 합니다.

[root@infra network-scripts]# nmcli conn reload
[root@infra network-scripts]#

 

nmcli명령으로 새로운 connection profile을 추가할 수 있습니다.

[root@bastion network-scripts]# nmcli conn add con-name "ens123" ifname empls0 type ethernet ip4 172.25.250.10/24 gw4 172.25.250.2
Connection 'ens123' (ad6222c2-1516-4144-b1f7-6a18be3fb9eb) successfully added.
[root@bastion network-scripts]# nmcli c s ens123
connection.id:                          ens123
connection.uuid:                        ad6222c2-1516-4144-b1f7-6a18be3fb9eb
...
ipv4.addresses:                         172.25.250.10/24
ipv4.gateway:                           172.25.250.2
ipv4.routes:                            --

[root@bastion network-scripts]# cd /etc/sysconfig/network-scripts/
[root@bastion network-scripts]# ls -l ifcfg*
-rw-r--r--. 1 root root 334 Jun  9 15:31 ifcfg-ens123
-rw-r--r--. 1 root root 221 Jun  3 14:00 ifcfg-eth0
-rw-r--r--. 1 root root 255 Jun  3 14:00 ifcfg-eth1
-rw-r--r--. 1 root root 254 Aug 19  2019 ifcfg-lo
-rw-r--r--. 1 root root 373 Jun  9 14:59 ifcfg-static-wired
[root@bastion network-scripts]# cat ifcfg-ens123
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=172.25.250.10
PREFIX=24
GATEWAY=172.25.250.2
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=ens123
UUID=ad6222c2-1516-4144-b1f7-6a18be3fb9eb
DEVICE=empls0
ONBOOT=yes

기존 설정을 수정할수도 있습니다.

[root@bastion network-scripts]# nmcli c mod ens123 ipv4.dns 172.25.250.254
[root@bastion network-scripts]# cat ifcfg-ens123
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=172.25.250.10
PREFIX=24
GATEWAY=172.25.250.2
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=ens123
UUID=ad6222c2-1516-4144-b1f7-6a18be3fb9eb
DEVICE=empls0
ONBOOT=yes
DNS1=172.25.250.254

2차 DNS를 추가할 때는 +ipv4.dns로 하시면 됩니다.

[root@bastion network-scripts]# nmcli c mod ens123 +ipv4.dns 8.8.8.8
[root@bastion network-scripts]# cat ifcfg-ens123
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=172.25.250.10
PREFIX=24
GATEWAY=172.25.250.2
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=ens123
UUID=ad6222c2-1516-4144-b1f7-6a18be3fb9eb
DEVICE=empls0
ONBOOT=yes
DNS1=172.25.250.254
DNS2=8.8.8.8
[root@bastion network-scripts]# nmcli c s ens123
connection.id:                          ens123
connection.uuid:                        ad6222c2-1516-4144-b1f7-6a18be3fb9eb
...
ipv4.dns:                               172.25.250.254,8.8.8.8
ipv4.dns-search:                        --
ipv4.dns-options:                       ""

 

변경사항을 적용하려면 connection을 재시작합니다.

[root@bastion network-scripts]# nmcli c reload
[root@bastion network-scripts]#

 

network connection profile을 삭제하려면 nmcli c delete를 사용하십시오.

[root@bastion network-scripts]# nmcli c s
NAME          UUID                                  TYPE      DEVICE
ens123        ad6222c2-1516-4144-b1f7-6a18be3fb9eb  ethernet  --
static-wired  b13f1fab-50d6-4625-9f25-70d473fde98e  ethernet  --
[root@bastion network-scripts]# nmcli c delete ens123
Connection 'ens123' (ad6222c2-1516-4144-b1f7-6a18be3fb9eb) successfully deleted.
[root@bastion network-scripts]# nmcli c reload
[root@bastion network-scripts]# nmcli c s
NAME          UUID                                  TYPE      DEVICE
static-wired  b13f1fab-50d6-4625-9f25-70d473fde98e  ethernet  --

 

이번에는 ifcfg파일을 직접 수정하여 하나의 connection에 대해 ip를 2개 부여하겠습니다.

먼저 새로운 network device를 추가합니다.

 

그리고, nmcli로 새로운 connection을 추가합니다.

[root@infra network-scripts]# nmcli d s
DEVICE  TYPE      STATE      CONNECTION
ens192  ethernet  connected  ens192
ens224  ethernet  connected  ?? ?? 1

[root@infra network-scripts]# nmcli c add con-name ens224 ifname ens224 type ethernet ip4 10.10.10.10 gw4 10.10.10.2 ipv4.dns 8.8.8.8
Connection 'ens224' (205c89c0-71ee-490a-b6c5-06f0c5508b99) successfully added.
[root@infra network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-ens224
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=10.10.10.10
PREFIX=32
GATEWAY=10.10.10.2
DNS1=8.8.8.8
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=ens224
UUID=205c89c0-71ee-490a-b6c5-06f0c5508b99
DEVICE=ens224
ONBOOT=yes
[root@infra network-scripts]# nmcli c reload
[root@infra network-scripts]# nmcli c up ens224
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
[root@infra network-scripts]# ip a
...
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:9f:23:b9 brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.10/32 brd 10.10.10.10 scope global noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet6 fe80::56d6:255b:fbdd:b1de/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

수동으로 ifcfg-ens224파일을 수정하여 2차IP를 부여합니다.

[root@infra network-scripts]# vi /etc/sysconfig/network-scripts/ifcfg-ens224

# IPADDR, PREFIX, GATEWAY에 일련번호를 붙여 ip를 추가함
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR0=10.10.10.10
PREFIX0=32
GATEWAY0=10.10.10.2
IPADDR1=172.168.10.10
PREFIX1=32
GATEWAY1=172.168.10.2
DNS1=8.8.8.8
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=ens224
UUID=205c89c0-71ee-490a-b6c5-06f0c5508b99
DEVICE=ens224
ONBOOT=yes

[root@infra network-scripts]# nmcli c reload
[root@infra network-scripts]# nmcli c up ens224
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)
[root@infra network-scripts]# ip a
...
3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:9f:23:b9 brd ff:ff:ff:ff:ff:ff
    inet 10.10.10.10/32 brd 10.10.10.10 scope global noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet 172.168.10.10/32 brd 172.168.10.10 scope global noprefixroute ens224
       valid_lft forever preferred_lft forever
    inet6 fe80::56d6:255b:fbdd:b1de/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

 

hostnamectl

host머신에 대한 정보를 리턴하거나 host명을 변경합니다.

root@infra network-scripts]# hostnamectl status
   Static hostname: infra
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 6491a71fa5d6430ea605f8d0efc33064
           Boot ID: 939b576c889347f8ba5e9421057dfc37
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1127.10.1.el7.x86_64
      Architecture: x86-64
[root@infra network-scripts]# hostnamectl set-hostname infraya
[root@infra network-scripts]# cat /etc/hostname
infraya
[root@infra network-scripts]# hostnamectl set-hostname infra
[root@infra network-scripts]#

 

nsswitch.conf: IP resolving 순서 정의

IP를 resolving 순서를 /etc/nsswitch.conf파일에 아래와 같이 정의할 수 있습니다.

아래 예는 /etc/hosts file을 먼저 참조하고, dns서버(/etc/resolv.conf)를 참조하는 설정입니다. 

[root@infra etc]# cat /etc/nsswitch.conf | grep hosts | egrep -v ^#
hosts:      files dns myhostname

예를 들어 아래와 같이 되어 있는경우...

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

10.10.10.10 ocean.kubepia.com ocean
172.168.10.165 infra.kubepia.com
[root@infra etc]# cat /etc/resolv.conf
# Generated by NetworkManager
search cp.kubepia.net
nameserver 10.178.41.148
nameserver 8.8.8.8

ocean을 찾으면 /etc/hosts에서 바로 찾고, ocean22를 찾으면 DNS서버까지 찾습니다.

[root@infra etc]# tracepath ocean
 1:  ocean.kubepia.com                                     0.070ms reached
     Resume: pmtu 65535 hops 1 back 1
[root@infra etc]# tracepath ocean22
 1?: [LOCALHOST]                                         pmtu 1500
 1:  api.cp.kubepia.net                                    0.489ms reached
 1:  api.cp.kubepia.net                                    0.365ms reached
     Resume: pmtu 1500 hops 1 back 1

 

getent

get entry의 약자로 특정 정보에서 keyword에 맞는 entry를 리턴합니다.  

주로 hosts에 설정된 entry를 찾을 때 편하게 사용할 수 있습니다. 

[root@infra etc]# getent services ssh
ssh                   22/tcp
[root@infra etc]# getent hosts ocean
10.10.10.10     ocean.kubepia.com ocean
댓글

클라우드 네이티브 애플리케이션 부트캠프 알림