Ubuntu Server / 고정 IP 설정하는 방법
Ubuntu
2020-09-14
차례
Ubuntu Server 22.04
설정 파일 수정하기
- 네트워크 설정 파일은 /etc/netplan 디렉토리 안에 있는 yaml 파일이다.
- DHCP로 설치했다면, 설정 파일 내용은 다음과 비슷하게 되어 있다.
# This is the network config written by 'subiquity' network: ethernets: eth0: dhcp4: true version: 2
- 다음과 같이 수정하고 저장한다. IP 등은 네트워크 환경에 맞게 적절히 수정한다.
- gateway 대신 routes를 사용합니다.
# This is the network config written by 'subiquity' network: ethernets: eth0: addresses: [192.168.0.227/24] routes: - to: default via: 192.168.0.1 nameservers: addresses: [8.8.8.8,8.8.4.4] version: 2
구 버전과 달라진 것은 gateway 대신 routes를 사용한다는 것이다.
- 다음과 같이 명령하면 설정 변경 사항이 적용된다.
netplan apply
GUI에서 설정하기
- 오른쪽 위의 네트워크 아이콘을 클릭하고, Wired Connected를 클릭하여 하위 메뉴를 확장하고, Wired Settings를 클릭한다.
- Network에서 설정 아이콘을 클릭한다.
- 적절히 설정하고 Apply를 클릭한다.
- 토글 버튼을 클릭하여 네트워크를 재시작한다.
만약 Wired Unmanaged라고 되어 있다면 네트워크 설정을 할 수 없다.
/etc/netplan 디렉토리 안에 있는 yaml 파일에 renderer: NetworkManager를 추가하면 해결된다.
# This is the network config written by 'subiquity' network: ethernets: eth0: dhcp4: true version: 2 renderer: NetworkManager
Ubuntu Server 20.04, Ubuntu Server 18.04
- 네트워크 설정 파일은 /etc/netplan 디렉토리 안에 있는 yaml 파일이다.
- DHCP로 설치했다면, 설정 파일 내용은 다음과 비슷하게 되어 있다.
# This is the network config written by 'subiquity' network: ethernets: enp0s3: dhcp4: true version: 2
- 다음과 같이 수정하고 저장한다. IP 등은 네트워크 환경에 맞게 적절히 수정한다.
# This is the network config written by 'subiquity' network: ethernets: enp0s3: addresses: [192.168.0.136/24] gateway4: 192.168.0.1 nameservers: addresses: [8.8.8.8,8.8.4.4] version: 2
- 다음과 같이 명령하면 설정 변경 사항이 적용된다.
netplan apply
Ubuntu Server 16.04
- 네트워크 설정 파일은 /etc/network/interfaces이다.
- 우분투를 DHCP로 설치했다면 설정 파일의 내용은 다음과 비슷하게 되어 있다.
# The primary network interface auto enp0s3 iface enp0s3 inet dhcp
- 이를 다음처럼 변경하고 저장한다. xxx.xxx.xxx.xxx는 네트워크 환경에 맞게 수정한다.
# The primary network interface auto enp0s3 iface enp0s3 inet static address xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx gateway xxx.xxx.xxx.xxx dns-nameservers xxx.xxx.xxx.xxx
- 다음과 같이 명령하여 네트워크를 재시작한다.
systemctl restart networking.service
- 만약 위와 같이 해도 IP가 바뀌지 않는다면 재부팅한다.