Linux/02.Ubuntu
[Ubuntu] 고정 IP 설정 하기
간마늘
2022. 7. 6. 10:54
0.개요
- Ubuntu는 18.04를 기준으로 고정 IP 설정 방법이 달라짐
- Ubuntu 18.04 이전 - networking 서비스로 제어
- Ubuntu 18.04 이후 - netplan으로 제어
1.Ubuntu 18.04 이전
cd /etc/network/
sudo vi interfaces
(전략)
# The primary network interface
auto eth0
# iface eth0 inet dhcp
iface eth0 inet static
address 192.168.0.40
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 8.8.8.8
- 파일 수정.
- eth0 : 네트워크 장치 이름
- dhcp : 자동 할당
- static : 수동 설정
- static 설정한 이후에 사용할 IP, Netmask, 게이트웨이, DNS 서버 설정 진행.
sudo service networking restart
(혹은)
sudo systemctl restart networking
- networking 서비스 재시작.
2.Ubuntu 18.04 이후
cd /etc/netplan/
sudo vi 01-network-manager-all.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses: [192.168.0.40/24]
gateway4: 192.168.0.1
nameservers:
addresses: [8.8.8.8,8.8.4.4]
- 파일 수정.
- eth0 : 네트워크 장치 이름
- dhcp : 자동 할당
- yes로 설정했으면 그 아래 설정들은 기입하지 않아도 됨.
- no로 설정했으면 사용할 IP, Netmask, 게이트웨이, DNS 서버 설정 진행.
sudo netplan apply
- Netplan 적용.