Skip to content

Debian:NetworkConfiguration

Using DHCP to automatically configure the interface

If you're just using DHCP then all you need is something like:

    auto eth0
    allow-hotplug eth0
    iface eth0 inet dhcp

For DHCPv6 (used for IPv6), append also the following iface stanza

    iface eth0 inet6 dhcp

Alternatively, IPv6 can be autoconfigured using stateless address autoconfiguration, or SLAAC, which is specified using auto instead of dhcp in the inet6 stanza:

    iface eth0 inet6 auto

Configuring the interface manually

If you're configuring it manually then something like this will set the default gateway (network, broadcast and gateway are optional):

    auto eth0
    iface eth0 inet static
        address 192.0.2.7/24
        gateway 192.0.2.254

If you want to add an IPv6 address, too, append something like:

    iface eth0 inet6 static
        address 2001:db8::c0ca:1eaf/64
        gateway 2001:db8::1ead:ed:beef

See man interfaces for more options.

Make sure to disable all DHCP services, e.g. dhcpcd.

Mixing manual and automatic configuration is also possible, e.g. to use IPv6 SLAAC for internet connectivity and static addresses within the network:

# manual unique local address
iface eth0 inet6 static
        address fdc3:cafe::3/64
        # use SLAAC to get global IPv6 address from the router
        # we may not enable ipv6 forwarding, otherwise SLAAC gets disabled
        autoconf 1
        accept_ra 2

Setting the speed and duplex

 iface eth0 inet static
        address .../...
        gateway ...
        up sleep 5; ethtool -s eth0 ...

Defining the (DNS) Nameservers

(친절한) 한글 예제

IP를 수정하기 위해서는 Ubuntu에서는 /etc/network/interfaces파일을 수정해야 합니다. 또는 /etc/network/interfaces.d/* 파일들을 확인해 보자.

auto lo eth0

# The loopback network interface
iface lo inet loopback

# The primary network interface (DHCP)
iface eth0 inet dhcp

정적 수정은 아래와 같이 수정하면 된다.

auto lo eth0
iface lo inet loopback
#iface eth0 inet dhcp
#기존 DHCP 는 안쓰기 때문에 주석처리 해놓는다.

iface eth0 inet static
#고정IP 방식을 사용하기 위해선 static 을 입력한다.

address 172.30.1.35
#내부 IP 주소나 외부 IP주소를 address 항목에 입력한다.

netmask 255.255.255.0
#서브넷 마스크를 입력한다.

broadcast 172.30.1.255
#브로드캐스트 IP를 입력한다. 대체적으로 끝자리가 255 이다.

gateway 172.30.1.254
#Gateway IP 를 입력한다. 공유기를 사용하는 경우 공유기 내부 환경설정을 위해 들어가는 IP 주소가 Gateway 이다.

dns-nameservers 168.126.63.1 168.126.63.2
#dns 서버를 입력한다. 스페이스바를 통해 보조DNS 설정이 가능하다. 첫번째가 메인 DNS, 두번째부터 서브 DNS 로 인식한다.

DNS서버 정보는 /etc/resolv.conf파일을 수정하면 된다.

nameserver 8.8.8.8
nameserver 8.8.4.4

다음 중 너가 사용하는 OS에 맞는 하나의 방법으로 네트워크를 재시작합니다.

  • sudo /etc/init.d/networking restart
  • sudo service network-manager restart
  • sudo systemctl restart networking.service
  • sudo systemctl restart systemd-networkd

명령행으로 적용하는 방법

First type netstat -I to find the interface name. Then type the below command:

sudo ifconfig eth0 192.168.72.6 netmask 255.255.255.0

Then to add a default gateway, add the below command:

sudo route add default gw 192.168.72.1 eth0

설정 파일 위치

명령행은 /etc/network/interfaces파일 또는 /etc/network/interfaces.d/* 파일들을 확인해 보자.

하지만 NetworkManager를 사용하고 있다면 /etc/NetworkManager/system-connections/* 경로에 존재할 것이다.

man page

  • man interfaces
  • man nmcli

See also

Favorite site