본문 바로가기

server/ubuntu 18.04

우분투 18.04 네트워크 고정 IP 할당 설정하기

개요

우분투를 설치하고 네티워크를 설정하는 방법에 대해서 알아보도록 하겠습니다.

고정 IP 설정하기

`01-netcfg.yaml` 파일 생성하기

root@localhost:~# vi /etc/netplan/01-netcfg.yaml

파일 내용 작성

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      # IP주소/서브넷마스크 설정
      addresses: [10.0.0.30/24]
      # 게이트웨이 설정
      gateway4: 10.0.0.1
      nameservers:
        # DNS서버 설정
        addresses: [10.0.0.10,10.0.0.11]
      dhcp6: no

설정 반영하기

root@localhost:~# netplan apply

IP주소 확인하기

root@localhost:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:19:e8:09 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.30/24 brd 10.0.0.255 scope global ens3
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe19:e809/64 scope link
       valid_lft forever preferred_lft forever

IPv6 비활성화 하기

IPv6를 사용하지 않을 경우 아래 명령어로 비활성화 할 수 있습니다. 

비활성화 명령어 실행

root@localhost:~# echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf

설정 확인

root@localhost:~# sysctl -p
net.ipv6.conf.all.disable_ipv6 = 1

root@localhost:~# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:19:e8:09 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.30/24 brd 10.0.0.255 scope global ens3
       valid_lft forever preferred_lft forever