Site icon Free Linux Tutorials

Basic Wired network interface configuration for popular Linux distribution

Basically, you just need to use the CLI command “ifconfig” which stands for interface configuration. It uses
to configure and query TCP/IP network interface parameters

ifconfig interface [aftype] options

where:

interface: eth0,eth1, em0
aftype: inet (default,TCP/IP), inet6(IPV6)
options: up,down, arp,promisc, mtu ##, broadcast xx.xx.xx.xx , netmask xx.xx.xx.xx

See the man page for more details

Common use of ifconfig:

Display info on all network interfaces, including active and active
#ifconfig -a

View network settings of specific interface
#ifconfig eth0

Disable an Interface
#ifconfig eth0 down

Enable an Interface
#ifconfig eth0 up

Assign IP address to interface
#ifconfig eth0 172.28.0.134

Assign IP, netmask and broadcast address at the same time to interface
e.g. eth0
#ifconfig eth0 172.28.0.134 netmask 255.255.255.240 broadcast 172.28.0.143

Normally, when I want to add or change IP address, I used this command, this should be enough even without adding the broadcast options
#ifconfig eth0 172.28.0.134 netmask 255.255.255.240 up

Notice I added the up at the end of the command to activates the interface

Semi-advanced commands like changing media type, speed and duplex settings is not covered on this tutorial. I’ll post another topic about it, but to give you a hint, you need to use mii-tool or the newer command ethtool.

Redhat/Fedora/CentOS

If you don’t want to use a menu type configuration via “setup” command, then you can configure manually by editing the files under /etc/sysconfig/network-scripts directory

[darwin@freelinux]$ ls /etc/sysconfig/network-scripts/
ifcfg-eth0 ifdown-aliases ifdown-isdn ifdown-sl ifup-ipsec ifup-plip ifup-routes init.ipv6-global
ifcfg-eth1 ifdown-ippp ifdown-post ifup ifup-ipv6 ifup-plusb ifup-sit network-functions
ifcfg-lo ifdown-ipsec ifdown-ppp ifup-aliases ifup-ipx ifup-post ifup-sl network-functions-ipv6
ifdown ifdown-ipv6 ifdown-sit ifup-ippp ifup-isdn ifup-ppp ifup-wireless

Edit the ifcfg-eth0 using your favorite text editor, here’s the sample:

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:AB:CD:EF:00:FL
IPADDR=172.28.0.134
NETMASK=255.255.255.240
ONBOOT=yes
TYPE=Ethernet

To take effect the changes, restart the network service

#service network restart

Debian/Ubuntu

For Debian & Ubuntu, network settings to edit is the
/etc/network/interfaces using your favorite text editor.

Here’s a sample content of /etc/network/interfaces

Static:
auto eth0
iface eth1 inet static
address 172.28.0.132
netmask 255.255.255.240

Dynamic or DHCP:
auto eth0
iface eth0 inet dhcp

To apply changes, restart the networking process
# /etc/init.d/networking restart

Gentoo

Network interfaces are configured under /etc/conf.d/net

Sample configuration:
Static
/etc/conf.d/net

#sample using netmask
config_eth0=”172.28.0.134 netmask 255.255.255.240″
routes_eth0=”default via 172.28.0.129″
dns_servers_eth0=”172.28.0.132″

#sample using CIDR
config_eth0=”172.28.0.134/28″
routes_eth0=”default via 172.28.0.129″
dns_servers_eth0=”172.28.0.132″

Dynamic
#sample dhcp config
config_eth0=”dhcp”

To apply changes, stop & start the interface
# /etc/init.d/net.eth0 stop
# /etc/init.d/net.eth0 start

Quick Tip:
Configure to load at boot
# rc-update add net.eth0 default
# rc

Suse/OpenSuse

Network configuration files are under the directory /etc/sysconfig/network/

Basically under this folder, you should look for ifcfg-eth*

Sample content for STATIC configuration:

BOOTPROTO=’static’
BROADCAST=”
ETHTOOL_OPTIONS=”
IPADDR=’172.28.0.134′
MTU=”
NAME=’Broadcom NetXtreme II BCM5708 Gigabit Ethernet’
NETMASK=’255.255.255.240′
NETWORK=”
REMOTE_IPADDR=”
STARTMODE=’auto’

Sample content for DHCP configuration:

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

To apply changes, restart networking service

# /etc/init.d/networking restart

Slackware

For wired configuration, a preferred way is to use “netconfig” tool to configure eth0. This will edit the rc.inet1.conf file which would be the same by editing manually the /etc/rc.d/rc.inet1.conf

Sample configuration for /etc/rc.d/rc.inet1.conf as follows:

# Config information for eth0:
IPADDR[0]=”172.28.0.134″
NETMASK[0]=”255.255.255.240″
USE_DHCP[0]=”no”
DHCP_HOSTNAME[0]=””

# Default gateway IP address:
GATEWAY=”172.28.0.129″

Exit mobile version