[ubuntu] ubuntu 18.04 Static IP 설정

ubuntu 18.04 Static IP 설정

 

 

ip 및 route 확인

root@test:~# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.146  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe21:fa45  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:21:fa:45  txqueuelen 1000  (Ethernet)
        RX packets 1081  bytes 1090726 (1.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 462  bytes 55353 (55.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 220  bytes 17184 (17.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 220  bytes 17184 (17.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


root@test:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.2     0.0.0.0         UG    100    0        0 ens33
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 ens33
192.168.0.2     0.0.0.0         255.255.255.255 UH    100    0        0 ens33
root@test:~#

 

ens33 device 설정

dhcp 사용시
root@test:~# cat /etc/netplan/50-cloud-init.yaml
network:
    ethernets:
        ens33:
            addresses: []
            dhcp4: true
    version: 2

static ip 사용시
root@test:~# vi /etc/netplan/50-cloud-init.yaml
network:
    ethernets:
        ens33:
            dhcp4: no
            addresses: [192.168.0.100/24]
            gateway4: 192.168.0.2
            nameservers:
              addresses: [8.8.8.8,1.1.1.1]
    version: 2
root@test:~# netplan apply
root@test:~# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.100  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::20c:29ff:fe21:fa45  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:21:fa:45  txqueuelen 1000  (Ethernet)
        RX packets 3349  bytes 1293093 (1.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2521  bytes 446805 (446.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 224  bytes 17428 (17.4 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 224  bytes 17428 (17.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

root@test:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.2     0.0.0.0         UG    0      0        0 ens33
192.168.0.0     0.0.0.0         255.255.255.0   U     0      0        0 ens33
root@test:~# ping kr.yahoo.com
PING src.san1.g01.yahoodns.net (106.10.248.151) 56(84) bytes of data.
64 bytes from w2.src1.vip.sg3.yahoo.com (106.10.248.151): icmp_seq=1 ttl=128 time=89.9 ms
64 bytes from w2.src1.vip.sg3.yahoo.com (106.10.248.151): icmp_seq=2 ttl=128 time=93.0 ms
^C
--- src.san1.g01.yahoodns.net ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 89.954/91.490/93.027/1.565 ms
root@test:~#

 

댓글 남기기