18.04 우분투 고정 IP 설정 방법

2020. 9. 19. 15:58IT 지식 공유/리눅스 서버

 

Ubuntu 18.04 고정 IP 설정

안녕하세요?

밀봉입니다.

 

오늘은 우분투 18.04 내에 docker를 설치하여 그 안에 서비스를 세팅할 예정입니다.

 

첫번째로 고정 IP를 설정 진행 후, 추후 서비스를 지속적으로 시리즈 업데이트 예정입니다.

 

1. 우분투의 네트워크 포트 설정은 [어댑터에 브리지]로 설정 진행

 

2. 우분투를 다시 올리고 고정 IP를 설정 해준다.

- 본인은 10.1.X.X 사설 IP로 진행 예정

 

3. 인터페이스 명을 확인 한다. [enp0s3]

ifconfig 명령어를 입력하여 아래와 같이 IP를 확인 한다.

ifconfig

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.1.10.130  netmask 255.255.255.0  broadcast 10.1.10.255
        inet6 fe80::a00:27ff:fe9a:e727  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:9a:e7:27  txqueuelen 1000  (Ethernet)
        RX packets 46661  bytes 2830045 (2.8 MB)
        RX errors 0  dropped 3  overruns 0  frame 0
        TX packets 104  bytes 14839 (14.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 92  bytes 7036 (7.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 92  bytes 7036 (7.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

4. 설정 파일을 루트 권한으로 열어서 수정 진행 한다.

sudo vi /etc/netplan/50-cloud-init.yaml

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            dhcp4: true
    version: 2

 

5. 아래와 같이 소스 코드 변경 후, [:wq] 명령어 사용하여 저장 후 종료

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    ethernets:
        enp0s3:
            addresses: [10.1.10.240/24]
            gateway4: 10.1.10.254
            nameservers:
                    addresses: [168.126.63.1,1.1.1.1]
            dhcp4: false
    version: 2

 

6. 변경된 설정으로 서비스 재시작

sudo netplan apply

 

7. 변경된 IP 주소 확인

ifconfig

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.1.10.240  netmask 255.255.255.0  broadcast 10.1.10.255
        inet6 fe80::a00:27ff:fe9a:e727  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:9a:e7:27  txqueuelen 1000  (Ethernet)
        RX packets 180752  bytes 10953887 (10.9 MB)
        RX errors 0  dropped 9  overruns 0  frame 0
        TX packets 916  bytes 135622 (135.6 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 92  bytes 7036 (7.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 92  bytes 7036 (7.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

기존의 DHCP로 할당 받앗던 10.1.10.130에서 10.1.10.240으로 변경된 것을 확인할 수 있다.