본문 바로가기
Development/Linux

[Linux] Ubuntu 사설 IP 변경 (고정 IP 할당) - 16.04, 20.04

by 성딱이 2021. 10. 22.
반응형

 

Ubuntu 16.04, Ubuntu 20.04 2가지 OS의 버전에 대해서 예제를 구성하였다.

From 192.168.0.x To 192.168.0.y

 

1. Ubuntu 16.04

1. 현재 네트워크 구성 확인

$ ifconfig
eno1    Link encap:Ethernet  HWaddr 40:b0:76:de:9b:a3
          inet addr:192.168.0.x  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:74466 errors:0 dropped:0 overruns:0 frame:0
          TX packets:60267 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:44575145 (44.5 MB)  TX bytes:10495549 (10.4 MB)
          Interrupt:16 Memory:a5300000-a5320000

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:3502 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3502 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:838383 (838.3 KB)  TX bytes:838383 (838.3 KB)

 

 

2. 사설 IP 설정 파일 확인 (/etc/network/interfaces)

sudo vi /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)

auto lo
iface lo inet loopback  >>> lo 라는 네트워크에 대해서 auto로 ip를 할당한다는 의미! 이 설정을 주석처리하고 바꾸고자 하는 ip로 고정할 예정! 

 

 

3. 설정 파일 내용 변경해주기 (eno1 네트워크의 ip에 대해서)

# interfaces(5) file used by ifup(8) and ifdown(8)

# auto lo
# iface lo inet loopback

auto eno1
iface eno1 inet static          # eno1 network를 고정으로 하겠다!
address 192.168.0.y             # 변경할 IP
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8 8.8.4.4 # 일단 이렇게 놓고 자세한 내용은 추가예정

 

 

4. 네트워크 재시작

$ sudo /etc/init.d/networking restart

 

 

5. 재부팅

$ sudo reboot

출처 : https://michael.mckinnon.id.au/2016/05/05/configuring-ubuntu-16-04-static-ip-address/

 

 

2. Ubuntu 20.04

From 192.168.0.x To 192.168.0.y

 

1. 현재 네트워크 구성 확인

$ ifconfig

or

$ ip addr show
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:ccff:fe59:7253  prefixlen 64  scopeid 0x20<link>
        ether 02:42:cc:59:72:53  txqueuelen 0  (Ethernet)
        RX packets 329  bytes 2135149 (2.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 787  bytes 91437 (91.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.x  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::f22f:74ff:fede:4067  prefixlen 64  scopeid 0x20<link>
        ether f0:2f:74:de:40:67  txqueuelen 1000  (Ethernet)
        RX packets 266436  bytes 38384285 (38.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 56826  bytes 7100697 (7.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xd5b00000-d5bfffff
 
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 14377  bytes 1241396 (1.2 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14377  bytes 1241396 (1.2 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
veth280a3cc: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::38ca:2cff:fe8f:aa32  prefixlen 64  scopeid 0x20<link>
        ether 3a:ca:2c:8f:aa:32  txqueuelen 0  (Ethernet)
        RX packets 329  bytes 2139755 (2.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1161  bytes 125408 (125.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

 

2. 사설 IP 설정 파일 확인 (/etc/netplan/01-network-manager-all.yaml)

$ sudo vi /etc/netplan/01-network-manager-all.yaml
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

 

 

3. 설정 파일 내용 변경해주기 (eno1 네트워크의 ip에 대해서)

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets :
          enp5s0:
                  addresses: [192.168.0.y/24]
                  gateway4: 192.168.0.1
                  nameservers:
                          addresses: [8.8.8.8,8.8.4.4]

 

 

4. 설정 변경사항 적용

$ netplan apply

 

 

5. 재부팅

$ sudo reboot
 

 

출처 1 : https://manualfactory.net/13079 

출처 2 : https://linuxize.com/post/how-to-configure-static-ip-address-on-ubuntu-20-04/ 

 

 

 

반응형

댓글