All About Debian /etc/network/interfaces File

Chưa phân loại
The file /etc/network/interfaces available in Debian and its derived distributions allows to define static and dynamic IP addresses for the interfaces, setup routing information and default gateways, masquerading network bonding and more.

The default interfaces file looks like the following:

Where auto starts the interface at boot and iface calls the network interface (in this case lo, loopback). All lines beginning with  “auto” specify the interfaces which will be enabled when running “ifup -a”, a command executed at boot.

Lines beginning with “iface” have the following syntax:

iface  <interface>  <address_family>  <method>

For example:

iface enp2s0 inet dhcp

The following example shows how to setup a network card using DHCP:

Setting up an interface with DHCP by editing the /etc/network/interfaces:

To add a new interface using DHCP, add the following lines:

auto <Interface>
allow-hotplug <Interface>
iface <Interface> inet dhcp

Where allow-hotplug will start the interface upon event detection.

Note: for IPv6 add “inet6”: iface <interface> inet6 dhcp

Where <interface> you should set your device name, eth0, enp2s0, wlp3s0, etc.

Setting up an interface with static address by editing the /etc/network/interfaces:

If instead of configuring the interface with DHCP you want to set a static IP address and gateway replace the previous instructions with the following (replace and with your correct IP addresses):

auto <Interface>
iface <Interface> inet static


Defining gateway and broadcast is optional.
The following example shows a different configuration which runs after the network interface is enabled (up) or disabled (down). The “up” lines are executed when the device is enabled while the “down” lines when it is disabled:

auto eth0
iface eth0 inet static
up route add -net netmask gw
up route add default gw
down route del default gw
down route del -net netmask gw

Setting up a network card with 2 interfaces:

The following example below shows a static configuration for a network card with two interfaces:

auto eth0 eth0:1
iface eth0 inet static
iface eth0:1 inet static

As you can see in this way you can assign multiple IP addresses to a single network interface.

Configure network bonding by editing the /etc/network/interfaces:

The following example shows my previous bonding mode 1 configuration within the /etc/network/interfaces file, I will leave interfaces with their names for easier understanding:

auto enp2s0
iface enp2s0 inet manual
bond-master bond0
bond-primary enp2s0 wlp3s0
auto wlp3s0
iface wlp3s0 inet manual
bond-master bond0
bond-primary enp2s0 wlp3s0
wpa-ssid ‘LinuxHint’
wpa-bssid ’14:CF:E2:2A:EF:00′
wpa-psk  ‘972537288765’
auto bond0
iface bond0 inet dhcp
bond-slaves none
bond-mode active-backup
bond-miimon 100
bond-downdelay 200
bond-updelay 200

A network bonding configuration with static IP instead of DHCP would have the last block like:

iface bond0 inet static

You can run the following command to make sure bonding is working properly:

# cat /proc/net/bonding/bond0

Source of examples: How to do Linux Network Bonding

Enable logging for the file /etc/network/interfaces:

There are 3 options related to the logging:

VERBOSE: instructs log files to have detailed information.
DEBUG: enable debugging when logging.
SYSLOG: save logs within /var/log/syslog.

Pre-up commands for /etc/network/interfaces: Pre-up commands are executed before enabling the network device. If the pre-up command fails the network card activation wont take place.

Post-up instructions for /etc/network/interfaces: Post-up instructions are executed after the network interface is enabled.

Pre-down instructions for /etc/network/interfaces: Pre-down instructions are executed before disabling the network device.

Post-down instructions for /etc/network/interfaces: Post-down instructions are executed after the network interface is disabled.

Pre-up, pre-down, post-up and post-down flags are conditional, if they ail the network device won’t get enabled or won’t be properly marked as disabled.

For example, the instruction:

pre-up /usr/local/sbin/iptables

Will run the firewall before the network interface gets enabled, if iptables fails to start the network interface wont turn on.

These instructions are optionals are valid for any method, they can be reiterated, alternatively if you want to run script when enabling and disabling network interfaces you can save them inside the directories:


The /etc/network/interfaces file is very complex with many more available options detailed at the main page or online at

I hope you found this brief article on About debian /etc/network/interfaces File useful.
Keep following LinuxHint for additional updates and tips on Linux and Networking.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Benchmark Hard Disks in Linux

Monitoring read and write speeds of storage devices is a good way to determine genuine products and determine disk health...

Installing Debian 10 Minimal Server

On a production server, you want only the bare minimum programs that are absolutely required for the proper function of...

How to install AnyDesk on Debian 10 Buster

AnyDesk portrays itself as the TeamViewer alternatives, despite TeamViewer offers compatibility and features superiority...
Bài Viết

Bài Viết Mới Cập Nhật

Check proxy trên trang nào chuẩn nhất❓

Thuê Proxy chạy Google Ads / Cần chú ý gì khi chọn proxy và email chạy G.G ads?

Thuê proxy 4G ở đâu uy tín, giá rẻ, chất lượng?

Vì sao cần thuê proxy xoay? Địa chỉ cung cấp proxy xoay uy tín

Thuê proxy v6 kéo view Youtube ở đâu uy tín, chất lượng?