Skip to content
Search

Debian:NetworkConfiguration

lastmod 2025-11-13created 2023-04-1211 edits

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

(Friendly) Korean example

To change the IP, on Ubuntu you need to edit the /etc/network/interfaces file. Alternatively, check the /etc/network/interfaces.d/* files.

auto lo eth0

# The loopback network interface
iface lo inet loopback

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

For a static configuration, edit it as follows.

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 로 인식한다.

For DNS server information, edit the /etc/resolv.conf file.

nameserver 8.8.8.8
nameserver 8.8.4.4

Restart the network using whichever one of the following methods fits your OS.

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

Applying from the command line

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

Configuration file location

For the command line, check the /etc/network/interfaces file or the /etc/network/interfaces.d/* files.

However, if you are using NetworkManager, they will be in the /etc/NetworkManager/system-connections/* path.

man page

  • man interfaces
  • man nmcli

See also

Favorite site

author Zer0 sitemap