/etc/network/interfaces Ubuntu Linux networking example

by on September 25, 2007 · 40 comments· LAST UPDATED September 25, 2007

in , ,

Q. Can you explain how to setup network parameters such as IP address, subnet, dhcp etc using /etc/network/interfaces file?

A. /etc/network/interfaces file contains network interface configuration information for the both Ubuntu and Debian Linux. This is where you configure how your system is connected to the network.

Defining physical interfaces such as eth0

Lines beginning with the word "auto" are used to identify the physical interfaces to be brought up when ifup is run with the -a option. (This option is used by the system boot scripts.) Physical interface names should follow the word "auto" on the same line. There can be multiple "auto" stanzas. ifup brings the named inter faces up in the order listed. For example following example setup eth0 (first network interface card) with 192.168.1.5 IP address and gateway (router) to 192.168.1.254:
iface eth0 inet static
address 192.168.1.5
netmask 255.255.255.0
gateway 192.168.1.254

Setup interface to dhcp

To setup eth0 to dhcp, enter:
auto eth0
iface eth0 inet dhcp

Examples: How to set up interfaces

Please read our previous
How to: Ubuntu Linux convert DHCP network configuration to static IP configuration
for more information.

Following is file located at /usr/share/doc/ifupdown/examples/network-interfaces, use this file as reference (don't forget interfaces man pages for more help):

######################################################################
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
#
# A "#" character in the very first column makes the rest of the line
# be ignored. Blank lines are ignored. Lines may be indented freely.
# A "\" character at the very end of the line indicates the next line
# should be treated as a continuation of the current one.
#
# The "pre-up", "up", "down" and "post-down" options are valid for all
# interfaces, and may be specified multiple times. All other options
# may only be specified once.
#
# See the interfaces(5) manpage for information on what options are
# available.
######################################################################
# We always want the loopback interface.
#
# auto lo
# iface lo inet loopback
# An example ethernet card setup: (broadcast and gateway are optional)
#
# auto eth0
# iface eth0 inet static
#     address 192.168.0.42
#     network 192.168.0.0
#     netmask 255.255.255.0
#     broadcast 192.168.0.255
#     gateway 192.168.0.1
# A more complicated ethernet setup, with a less common netmask, and a downright
# weird broadcast address: (the "up" lines are executed verbatim when the
# interface is brought up, the "down" lines when it's brought down)
#
# auto eth0
# iface eth0 inet static
#     address 192.168.1.42
#     network 192.168.1.0
#     netmask 255.255.255.128
#     broadcast 192.168.1.0
#     up route add -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
#     up route add default gw 192.168.1.200
#     down route del default gw 192.168.1.200
#     down route del -net 192.168.1.128 netmask 255.255.255.128 gw 192.168.1.2
# A more complicated ethernet setup with a single ethernet card with
# two interfaces.
# Note: This happens to work since ifconfig handles it that way, not because
# ifup/down handles the ':' any differently.
# Warning: There is a known bug if you do this, since the state will not
# be properly defined if you try to 'ifdown eth0' when both interfaces
# are up. The ifconfig program will not remove eth0 but it will be
# removed from the interfaces state so you will see it up until you execute:
# 'ifdown eth0:1 ; ifup eth0; ifdown eth0'
# BTW, this is "bug" #193679 (it's not really a bug, it's more of a
# limitation)
#
# auto eth0 eth0:1
# iface eth0 inet static
#     address 192.168.0.100
#     network 192.168.0.0
#     netmask 255.255.255.0
#     broadcast 192.168.0.255
#     gateway 192.168.0.1
# iface eth0:1 inet static
#     address 192.168.0.200
#     network 192.168.0.0
#     netmask 255.255.255.0
# "pre-up" and "post-down" commands are also available. In addition, the
# exit status of these commands are checked, and if any fail, configuration
# (or deconfiguration) is aborted. So:
#
# auto eth0
# iface eth0 inet dhcp
#     pre-up [ -f /etc/network/local-network-ok ]
#
# will allow you to only have eth0 brought up when the file
# /etc/network/local-network-ok exists.
# Two ethernet interfaces, one connected to a trusted LAN, the other to
# the untrusted Internet. If their MAC addresses get swapped (because an
# updated kernel uses a different order when probing for network cards,
# say), then they don't get brought up at all.
#
# auto eth0 eth1
# iface eth0 inet static
#     address 192.168.42.1
#     netmask 255.255.255.0
#     pre-up /path/to/check-mac-address.sh eth0 11:22:33:44:55:66
#     pre-up /usr/local/sbin/enable-masq
# iface eth1 inet dhcp
#     pre-up /path/to/check-mac-address.sh eth1 AA:BB:CC:DD:EE:FF
#     pre-up /usr/local/sbin/firewall
# Two ethernet interfaces, one connected to a trusted LAN, the other to
# the untrusted Internet, identified by MAC address rather than interface
# name:
#
# auto eth0 eth1
# mapping eth0 eth1
#     script /path/to/get-mac-address.sh
#     map 11:22:33:44:55:66 lan
#     map AA:BB:CC:DD:EE:FF internet
# iface lan inet static
#     address 192.168.42.1
#     netmask 255.255.255.0
#     pre-up /usr/local/sbin/enable-masq $IFACE
# iface internet inet dhcp
#     pre-up /usr/local/sbin/firewall $IFACE
# A PCMCIA interface for a laptop that is used in different locations:
# (note the lack of an "auto" line for any of these)
#
# mapping eth0
#    script /path/to/pcmcia-compat.sh
#    map home,*,*,*                  home
#    map work,*,*,00:11:22:33:44:55  work-wireless
#    map work,*,*,01:12:23:34:45:50  work-static
#
# iface home inet dhcp
# iface work-wireless bootp
# iface work-static static
#     address 10.15.43.23
#     netmask 255.255.255.0
#     gateway 10.15.43.1
#
# Note, this won't work unless you specifically change the file
# /etc/pcmcia/network to look more like:
#
#     if [ -r ./shared ] ; then . ./shared ; else . /etc/pcmcia/shared ; fi
#     get_info $DEVICE
#     case "$ACTION" in
#         'start')
#             /sbin/ifup $DEVICE
#             ;;
#         'stop')
#             /sbin/ifdown $DEVICE
#             ;;
#     esac
#     exit 0
# An alternate way of doing the same thing: (in this case identifying
# where the laptop is is done by configuring the interface as various
# options, and seeing if a computer that is known to be on each particular
# network will respond to pings. The various numbers here need to be chosen
# with a great deal of care.)
#
# mapping eth0
#    script /path/to/ping-places.sh
#    map 192.168.42.254/24 192.168.42.1 home
#    map 10.15.43.254/24 10.15.43.1 work-wireless
#    map 10.15.43.23/24 10.15.43.1 work-static
#
# iface home inet dhcp
# iface work-wireless bootp
# iface work-static static
#     address 10.15.43.23
#     netmask 255.255.255.0
#     gateway 10.15.43.1
#
# Note that the ping-places script requires the iproute package installed,
# and the same changes to /etc/pcmcia/network are required for this as for
# the previous example.
# Set up an interface to read all the traffic on the network. This
# configuration can be useful to setup Network Intrusion Detection
# sensors in 'stealth'-type configuration. This prevents the NIDS
# system to be a direct target in a hostile network since they have
# no IP address on the network. Notice, however, that there have been
# known bugs over time in sensors part of NIDS (for example see
# DSA-297 related to Snort) and remote buffer overflows might even be
# triggered by network packet processing.
#
# auto eth0
# iface eth0 inet manual
# 	up ifconfig $IFACE 0.0.0.0 up
#       up ip link set $IFACE promisc on
#       down ip link set $IFACE promisc off
#       down ifconfig $IFACE down
# Set up an interface which will not be allocated an IP address by
# ifupdown but will be configured through external programs. This
# can be useful to setup interfaces configured through other programs,
# like, for example, PPPOE scripts.
#
# auto eth0
# iface eth0 inet manual
#       up ifconfig $IFACE 0.0.0.0 up
#       up /usr/local/bin/myconfigscript
#       down ifconfig $IFACE down
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 40 comments… read them below or add one }

1 mandatoryfields January 12, 2008 at 3:47 pm

Thanks for the info I struggled forever with wierd behaviour after reboot with my NIC until I found this info. I didn’t even know this file existed and although everything si not fixed with the NIC atleast all apps poin to the right interface and it holds an IP address instead of jumpin to dhcp all the time or shoeing “The interface does not exist” Very annoying message that

Reply

2 mandatoryfields January 12, 2008 at 3:48 pm

should point out, those are NIC plural

Reply

3 Csmith March 15, 2008 at 4:34 pm

Every time I add the following lines, Ubuntu takes a long time to show the logon screen, and the nic is down after logon:

auto eth0
iface eth0 inet dhcp

Without these lines, everything works fine, but I’m trying to add these lines in an attempt to fix the following problem with logons via Active Directory accounts. (Whenever the pc is rebooted, users get a “no logon servers available” error and can’t logon via AD unless I logon a local account and manually restart samba and winbind in the terminal. I’m under the impression that adding these lines to “/etc/network/interfaces” may bring up dhcp sooner and get the pc on the network before samba and winbind start.)

In any case, the lines above seem to mess things up even more, but if anyone has any ideas . . .

Reply

4 HumanUmbrella August 2, 2008 at 7:36 pm

Csmith, Try reversing the order of the two statements

Reply

5 not you August 12, 2008 at 6:57 pm

Csmith,

Are you sure you are using an eth0 instead of an eth1?

Reply

6 Kim SJ September 30, 2008 at 9:09 pm

Use man interfaces for more info on the syntax

Reply

7 ubuntunewbie October 31, 2008 at 11:59 am

I just installed ubuntu 8.04, trying to manually enter the network configuration, but ubuntu doesn’t show up any nic card and manuall static ip configuration doesn’t work, I have installed CENTos on different machine, usually it shows something like eth0. One more thing, I am able to connect to internet/Lan if I choose “roaming profile” – any help is appreciated..

thanks

Reply

8 lambda_belka November 23, 2008 at 8:07 pm

Great manual! Thx.

A link on similar explicit confs for wireless would be great. Anybody?
Thanks in advance.

Reply

9 Efriel December 19, 2008 at 3:58 pm

its very helpful thanks

Reply

10 John January 16, 2009 at 10:47 pm

Brilliant!
I was comparing mine with this – found a typo as a result “etho” vs “eth0″
Thanks for the virtual second set of eyes!

Reply

11 GregTheGerg January 25, 2009 at 9:58 pm

Hey, I had a question, I am trying to setup a Ubuntu 8.10 server with my PC on a WLAN. I was just wondering how to set it up since I have WPA2 Personal, AES encrypted WLAN in the middle. I would like to be abe to connect it to that WLAN, how do I configure it?

Reply

12 bob February 22, 2009 at 6:33 am

what do tou mean by /path/to/check-mac-address.sh?

Reply

13 Gilera May 24, 2009 at 2:30 pm

How about configuring > 1 NIC in PC. Any related multipath tutorial?

Reply

14 nixCraft May 24, 2009 at 2:33 pm

Are you talking about storage?

Reply

15 Mogga June 22, 2009 at 7:41 am

How can I extend the two interface on one NIC example above to bridge a set of virtual servers on a host machine with the two interfaces on two different networks?
Am I looking for a bridge setup or is it more suited to tun/tap?
Here’s where I’ve started:

auto eth0 eth0:1
# physical network connected to my ISP router
iface eth0 inet static
address 192.168.1.50
network 192.168.1.0
netmask 255.255.255.0
gateway 192.168.1.254

# virtual network interface for servers
iface eth0:1 inet static
address 10.1.0.1
network 10.1.0.0
netmask 255.255.0.0

So now I need a bridge etc. to connect the physical and virtual machines!
Not sure where to get started…

Reply

16 nixCraft June 22, 2009 at 8:48 am

Are virtual IPs part of cluster?

Reply

17 Susanne Blond June 29, 2009 at 2:24 pm

Great manual. Thank you for your work.

Reply

18 Urederra August 17, 2009 at 7:19 pm

And how do you tell the system what the network password is?

Reply

19 Timmy November 14, 2009 at 2:44 pm

I think Ubuntu has abandoned /etc/network/interfaces in favour of /etc/NetworkManager/system-connections/ , which is edited by the rather handy GUI tool System > Preferences > Network Connections.

Reply

20 ┼Żan October 13, 2012 at 3:30 pm

I think you are very sure that is indeed true. Though I actually don’t even know about the new version i can tell you 1 big problem you missed out. We don’t use gnome, or kde, … Sometimes things are best left to the professionals…

Reply

21 Anonymous March 17, 2010 at 6:39 am

Why the hell have you forgotten the dns settings?
Don’t you realise that not including the dns settings you won’t be able to surf the internet?

You need to insert the dns as follows:
dns-nameserver xxx.xxx.xxx.xxx
Where xxx.xxx.xxx.xxx is the ip address of your isp nameserver

Reply

22 Pannaga Bhushan June 24, 2013 at 8:50 am

You need to insert the dns as follows:
dns-nameservers xxx.xxx.xxx.xxx
Where xxx.xxx.xxx.xxx is the ip address of your isp nameserver

Reply

23 norb April 26, 2010 at 6:51 pm

ubuntu has not abandoned /etc/network/interfaces, NetworkManager just handles interfaces NOT mentioned in that file.

However, I’m by far no expert, using ubuntu for years, starting my first ubuntu-server.
I don’t want much (SSH from Internet to my Machine, and from there in the network to my desktop) and it works sometimes.

I only configured interfaces, no bridge, no route.
eth1 is internet (router), eth0 network per dhcp (router).
How should i proceed?

Reply

24 timecmdr July 20, 2010 at 9:06 am

Anon – The DNS settings reside in the /etc/resolv.conf file thats why they are not mentioned here.

They are set via DHCP if your using it otherwise you’ll need to add them manually.

Timecmdr

Reply

25 yo August 28, 2010 at 1:16 am

#: nano /etc/network/interfaces

##edit eth1 your dispositive
auto eth1
iface eth1 inet dhcp
##save

#:/etc/init.d/networking restart

Reply

26 Zach September 13, 2010 at 3:50 pm

Does anyone know if there exists a way to test a large file full or static IP aliases (about 30) and custom, static routes (about 80) for conflicts or issues without doing a network restart (and risking the interfaces not coming back up correctly)?

Reply

27 HSAIN November 10, 2010 at 10:48 pm

how to edit and save this changes. I use nano command to edit but it can’t be saved.
(nano etc/network/interfaces)

Reply

28 Ash Rocks November 29, 2010 at 5:26 pm

Ctrl + X buddy, It should help you save the edited file.
But its a good practice to take a backup of the file before editing.
Hope this helps.

Reply

29 Jeff Block May 8, 2013 at 2:09 pm

Try:

sudo nano /etc/network/interfaces

Reply

30 Aaron Zacharkiw November 30, 2010 at 11:06 pm

My etc/network/interfaces file is completly blank. Can someone tell me how to get a DCHP connection set up along with a loopback address?

Reply

31 nikobe January 18, 2011 at 9:29 pm

Big thank you your example fixed my network woes after I fiddled with VPN settings and ended up with a dodgy connection.

:)

Reply

32 Nick February 10, 2011 at 4:02 pm

Thanks for the article, very useful.
I’ve got a question to put out there:

I have a modified verison of linux (Ubuntu) installed (provided by a 3rd party). When running ifconfig -a, I can see that I have 2 IP’s configured to eth0 (one to eth0 and one to eth0:1).

They are both up, ‘ping-able’, and survive reboots.

My question is, my /etc/network/interfaces file only contains the information for eth0 (and lo) but with no reference to eth0:1. How can this be? Where else could eth0:1 be set?

Reply

33 AnonymousCoward April 27, 2011 at 11:55 am

I had a similar issue. I ended up searching for the settings in my home directory with a command like this:
grep -R .
I found a file called all in my home directory with contents similar to /etc/network/interfaces. Deleting solved my problem.

Reply

34 zL July 31, 2011 at 12:52 pm

Thanks! This article is just what I was looking for.
Much appreciated!

Reply

35 joem September 10, 2011 at 10:40 am

Two ethernet interfaces, one connected to a trusted LAN, the other to
the untrusted Internet.

how to I configure this one.? right now Im having a problem on this one.

this is what i wrote on /etc/networ/interfaces

auto eth1
iface eth1 inet static
address 192.168.0.1
netmask 255.255.255.0

and nothing follow and i configure already my dhcpd.conf

Reply

36 Sathishkumar January 19, 2012 at 12:04 pm

Thank you so much cyberciti..

Reply

37 nuur wahid anshary July 9, 2012 at 8:21 am

Thanks . . . this article fixes my problem. . . .

Reply

38 Prahlad Yeri August 6, 2012 at 5:04 pm

Well, ideally it should be “allow-hotplug eth0″ instead of “auto eth0″. This way, ethernet card is configured only when the kernel detects a hotplug event from it. At least debian configures the NIC in this way when you install it: http://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_gui_network_configuration_tools

Reply

39 ted December 3, 2013 at 1:12 pm

I also have a dns-domain entry. Does that make sense?

dns-domain somedomain.com

Reply

40 hooongwing December 26, 2013 at 7:49 pm

thank you. guess i should get to RTFMing more.

Reply

Leave a Comment

Tagged as: , , , , , , , , , , ,

Previous Faq:

Next Faq: