Ubuntu 네트워크 설정(20.04, 18.04)

2022. 1. 12. 15:45프로그래밍 개발(Development)/Linux

반응형

ubuntu 20.04 기준으로 네트워크 설정 방법

 

1. /etc/netplan/ 안에 있는 yaml 파일에 네트워크가 설정 되어 있다.

 - 처음 설치 시에는 아래와 같이 dhcp 방식으로 설정이 되어 있다.

# This is the network config written by 'subiquity'
network:
  ethernets:
    ens33:
      dhcp4: true
  version: 2

고정 IP로 변경 하기 위해서는 아래와 같이 변경을 해주면 된다.

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s3:
      addresses: 
        - 192.168.0.10/24
      gateway4: 192.168.0.1
      nameservers:
        addresses:
        	- 8.8.8.8
  version: 2

adresses와 nameservers의 경우에는 배열이기 때문에 아래와 같이 설정을 할 수도 있다.

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp0s3:
      addresses: [192.168.0.10/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
  version: 2

 변경 사항 적용

$ netplan apply

ubuntu 18.04 기준으로 네트워크 설정 방법

 

1. interface 확인

예) eth0, ens1 등으로 나타남

$ ip addr 
or 
$ ifconfig

2. VI 에디터로 인터페이스 파일을 오픈

$ vi /etc/network/interfaces

3. dhcp (자동) 설정

    eth0 부분을 실제 사용하는 인터페이스 명으로 입력

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

4. static (고정) 설정

# The primary network interface
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 10.10.10.123
netmask 255.255.255.0
gateway 10.10.10.1
dns-nameservers 8.8.8.8

5. Network restart (재시작)

$ service networking restart

6. Network 재시작 실패시 아래의 명령어 입력

$ ifdown eth0 && sudo ifup eth0
반응형