User Tools

Site Tools


linux:sysadmin:net:network_configuration

Network Configuration

Commands

Command Description
echo “1” > /proc/sys/net/ipv4/ip-forwardenable IP forwarding for router functinonality
ifconfigshow configuration of network interfaces
ifconfig <interface> downdisable a network interface
route add default gw <IP>add a default gateway to the routing table
route del default gw <IP>delete default gateway
route -n show local routing table
netstat -rn show local routing table

Activating deactivating Interfaces

ifdown eth0
ifup eth0

Configuring DNS

edit /etc/resolve.conf, see the example configuration below:

search niwos.com
nameserver 192.168.1.10
nameserver 192.168.1.11

Configuring default gateway

Setting up default gateway manually:

route add default gw <IP>

Edit /etc/sysconfig/network to configure the default gateway permanently. Example file (GATEWAY ⇒ default gateway):

NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=eul0001207vmb
GATEWAY=83.231.177.238

To see the changes, restart the network service:

service network restart

Changing bootup scripts

Setting persistent routes

For each device, ethX, create the file /etc/sysconfig/network-scripts/route-ethX.

The contents should be like:

10.0.1.0/24 via 192.168.2.4 dev eth0
10.0.4.0/24 via 192.168.2.2 dev eth0

Example config file for eth2 routes to the databases:

Create a file named “route-eth2”. The config will be read on interface boot up.

192.168.63.32/27 via 192.168.63.254
192.168.63.0/27 via 192.168.63.254

Config with fixed IP address

Example config from /etc/sysconfig/network-scripts/ifcfg-eth0:

#
# File: ifcfg-eth0
#
DEVICE=eth0
IPADDR=192.168.1.100
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
#
# The following settings are optional
#
BROADCAST=192.168.1.255
NETWORK=192.168.1.0

Config with DHCP

Example from /etc/sysconfig/network-scripts/ifcfg-eth0:

#
# File: ifcfg-eth0
#
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

DHCP config with fixed dns

This configuration prevents /etc/resolv.conf being overwritten with wrong values:

# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
DNS1=213.130.44.252
DNS2=213.198.55.2
DNS3=81.19.96.148
DNS4=81.25.192.148
HWADDR=00:0c:29:29:52:77

Change interface speeed

Show the interface speed of your network cards:

mii-tool

Change interface speed on 100Mbits full duplex:

mii-tool -F 100baseTx-FD eth0

Change network interface name

  1. Change the interface name
    1. Under CentOS/RedHat you have to add the MAC-address in /etc/sysconfig/network-scripts/ifcfg-eth* to pin a interface to a certain name.
    2. For Debian systems edit the interface name directly in the udev file (typically found under /etc/udev/rules.d/*-net.rules).
  2. Restart the server

Change the server hostname

Change the host name in the following files:

  1. /etc/sysconfig/network
  2. /etc/hosts

Restart the network service:

service network restart

Set the hostname without reboot:

hostname -v new_hostname
/srv/wiki.niwos.com/data/pages/linux/sysadmin/net/network_configuration.txt · Last modified: 2011/03/02 10:51 (external edit)