Ubuntu 24.04 LTS 고정 IP설정하기

 

안녕하세요. 달소입니다.

 

이번글에서는 앞서 설치한 Ubuntu 24에서 고정 ip를 설정하는방법입니다.

기본적으로 Ubuntu 20인가부터 netplan을 사용하기 시작했기때문에 설정방법은 모두 대동소이하나 기록용으로 남겨봅니다.

 

최초에 dhcp로 설정한 경우에는 헷갈릴수도있으니까요.

 

기본 vi 에디터가 없으면 apt install vim 으로 설치해주시면됩니다.

 

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

 

 DHCP로 설치하신경우 기본적으로 아래와같이 되어있는데요.

 

image.png.jpg

 

해당 값들을 아래처럼 바꿔주시면 됩니다.

 

인터페이스는 ifconfig 명령어로 확인해주시고 설정해주세요.

 

image.png.jpg

 

address: 는 ip와 서브넷마스크를 의미합니다.

nameservers:는 dns이고

routes:는 디폴트라우팅 설정입니다.

 

# 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:
        ens18:
            addresses:
            - 192.168.1.23/24
            nameservers:
                addresses:
                - 1.1.1.1
                search:
                - 8.8.4.4
            routes:
            -   to: default
                via: 192.168.1.1
    version: 2

 

설정 후 netplan apply로 적용을 해주시면되는데

주의할점은 기존연결한 ip가 구 ip라면 연결이 끊기기때문에 가급적 콘솔에서 작업해주시는게 좋습니다.

 

image.png.jpg

 

ip가 바뀌면 아래처럼 다시 로그인하실 수 있습니다.

 

image.png.jpg