Network Setup Tips: Difference between revisions

From MediaWiki
Jump to navigationJump to search
Line 304: Line 304:
   }
   }
  done
  done
eno16777736
/sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0

Revision as of 08:06, 24 December 2013

NST Script: nstnetcfg

See page: HowTo Setup a Server With Multiple Network Interface Adapters Using: "nstnetcfg" for a simplified means of setting up networking on an NST system.

Accessing Network Configuration Files

To easily access the network configuration files, simply use the bash alias: "cdnet":

[root@probe ~]# cdnet
[root@probe network-scripts]# 
[root@probe ~]# pwd
/etc/sysconfig/network-scripts
[root@probe network-scripts]# 

 

NST Script: nstnetcfg

HowTo_Setup_A_Server_With_Multiple_Network_Interface_Adapters_Using:_"nstnetcfg"

How To Specify A Host Name To A DHCP Server

Some times it is desirable to specify a host name at the DHCP Client to be recognized by the DHCP Server. This will allow for local host names to be resolved by their respective name on the local LAN. This works well with a DD-WRT enabled LinkSys router and bind.

To do this, add the following line to your network configuration file (Example for: eth0 - We will use file: "/etc/sysconfig/network-scripts/ifcfg-eth0" and request that the DHCP server set this system's host name to: "emachine".):

DHCP_HOSTNAME=<Your desired host name for this NST DHCP client>

Both the "network" service and the NetworkManager service support this setting for DHCP.

Listing: "/etc/sysconfig/network-scripts/ifcfg-eth0"
[root@probe-biostar network-scripts]# cat "/etc/sysconfig/network-scripts/ifcfg-eth0"
#
# DHCP Client Config: eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes

#
# Disable capabilities security feature when running dhclient so we
# can run the NST dhclient exit hook script: "/etc/dhcp/dhclient.d/nst.sh".
DHCLIENTARGS="-nc"

#
# Specify the 'dhclient' host-name option (-H) to send to the DHCP server.
DHCP_HOSTNAME=emachine

 

How To Permanently Set The Host Name Of Your NST System

To do this, add/change the following line to the system configuration file: "/etc/sysconfig/network"

HOSTNAME=<your desired host name for this NST system>

NetworkManager will be notified of this change and automatically set the system "hostname". The example below sets the system host name to: "emachine". Typically, if this system is a DHCP client, both the "DHCP_HOSTNAME" discussed above and the "HOSTNAME" entries are set identically.

Listing: "/etc/sysconfig/network"
[root@probe-biostar sysconfig]# cat "/etc/sysconfig/network"
NETWORKING=yes
HOSTNAME=emachine
NOZEROCONF=yes

A system reboot can be done to verify all changes.

Note on Setting the Host Name when Using DHCP to get the IP Address: NST is configured to run the dhclient exit hook script: "/etc/dhcp/dhclient.d/nst.sh". This script will try to automatically set the system's host name based on results from DHCP. Avoid using "probe-" as the first 6 characters in the "HOSTNAME" parameter above (e.g., probe-sys1 - Instead use: sys1-probe). These characters are reserved by NST.

 

Configuring A Static IP Address

If the network your interface is connected to does not have a DHCP server, you will need to configure your system to use a static IP address. The following shows the contents of file: "/etc/sysconfig/network-scripts/ifcfg-eth0" which is used to assign a static IP address of: "192.168.12.100" to eth0 (an Ethernet interface):

DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.12.100
NETMASK=255.255.255.0
NETWORK=192.168.12.0
BROADCAST=192.168.12.255
GATEWAY=192.168.12.1
ONBOOT=yes
Note 1: The above assumes that the gateway machine for the network has an IP address of: "192.168.12.1" on network: "192.168.12.0/24".

Note 2: Make sure the NetworkManager" service is disabled: systemctl disable NetworkManager.service;

Note 3: Make sure the "network" service is enabled: systemctl enable network.service;

 

Configuring A Stealth Network Interface

In order to configure a stealth (i.e., A network interface with a non-binding IP Address) network interface set the BOOTPROTO setting to: "none". Example: Make network interface: "eth1" at stealth interface using this minimal configuration:

DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes

 

Restarting the Network Service

After editing any network configuration file, you should restart the network service as shown below:

Restarting the Network Service (service command)
[root@probe-biostar network-scripts]# service network restart
[root@tmobile network-scripts]# service network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
[root@probe-biostar network-scripts]#

For "NST 15" and above use the systemctl command:

Restarting the Network Service (systemctl command)
[root@probe-biostar network-scripts]# systemctl restart network.service
[root@tmobile network-scripts]# systemctl restart network.service
[root@probe-biostar network-scripts]#

 

Display Routing Table

The following command can be used to display your network routing table (the -n option was included to prevent the route command from trying to resolve names):

Display Routing Table
[root@dhcp121 ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
[root@dhcp121 ~]#

 

IP Aliasing (Multi-Net)

Overview

An IP Alias allows you to configure multiple IP Addresses onto a physical device (NIC). IP aliasing is known as network layer virtual hosting. It is common to use an IP Aliases with Apache Virtual Hosting.

HowTo Add An IP Alias

IP Alias Add Example: (NIC: p5p1, Alias: p5p1:0)
[root@shopper2 ~]# ifconfig
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:580 errors:0 dropped:0 overruns:0 frame:0
          TX packets:580 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:44887 (43.8 KiB)  TX bytes:44887 (43.8 KiB)

p5p1      Link encap:Ethernet  HWaddr E0:69:95:B1:6E:BF  
          inet addr:10.222.222.10  Bcast:10.222.222.255  Mask:255.255.255.0
          inet6 addr: fe80::e269:95ff:feb1:6ebf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:146101 errors:0 dropped:19 overruns:0 frame:0
          TX packets:71495 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:80187453 (76.4 MiB)  TX bytes:44001889 (41.9 MiB)
          Interrupt:46 Base address:0x6000 
  
[root@shopper2 ~]# ifconfig p5p1:0 10.222.222.83/24
[root@shopper2 ~]# ifconfig
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:580 errors:0 dropped:0 overruns:0 frame:0
          TX packets:580 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:44887 (43.8 KiB)  TX bytes:44887 (43.8 KiB)

p5p1      Link encap:Ethernet  HWaddr E0:69:95:B1:6E:BF  
          inet addr:10.222.222.10  Bcast:10.222.222.255  Mask:255.255.255.0
          inet6 addr: fe80::e269:95ff:feb1:6ebf/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:146101 errors:0 dropped:19 overruns:0 frame:0
          TX packets:71495 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:80187453 (76.4 MiB)  TX bytes:44001889 (41.9 MiB)
          Interrupt:46 Base address:0x6000

p5p1:0    Link encap:Ethernet  HWaddr E0:69:95:B1:6E:BF  
          inet addr:10.222.222.83  Bcast:10.222.222.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:46 Base address:0x6000 
  
[root@shopper2 ~]#

The IP Alias command above produced a virtual host address for the p5p1 network interface using IP Address: "10.222.222.83". IP Aliases are referred to by appending ":n" to the actual network interface device, in which "n" is an integer. In our example, we created the IP Alias on NIC: "p5p1" , with alias number "Zero (0)".

All network statistics associated with each IP Alias interface are combined with the physical network interface. To get individual statistics for an IP Aliased Interface then accounting rules would need to be used through the iptables command.

HowTo Remove An IP Alias

To remove an IP Alias use the ifconfig command "down" option:

IP Alias Remove Example1: (NIC: p5p1, Alias: p5p1:0)
[root@shopper2 ~]# ifconfig p5p1:0 down
  
[root@shopper2 ~]#

 

HowTo Permanently Add An IP Alias

This procedure uses the "network" service. The following shows the contents of file: "/etc/sysconfig/network-scripts/ifcfg-p5p1:0" which is used to assign a static IP Alias address of: "10.222.222.83" to network interface: "p5p1:0"

DEVICE=p5p1:0
BOOTPROTO=static
IPADDR=10.222.222.83
NETMASK=255.255.255.0
NETWORK=10.222.222.0
BROADCAST=10.222.222.255
GATEWAY=10.222.222.1
ONBOOT=yes
Note 1: The above assumes that the gateway machine for the network has an IP address of: "10.222.222.1" on network: "10.222.222.0/24".

Note 2: Make sure the NetworkManager" service is disabled: systemctl disable NetworkManager.service;

Note 3: Make sure the "network" service is enabled: systemctl enable network.service;


Create Predictable Network Interface Names

Some information in this section was derived from the site: freedesktop.org.

Overview

Starting with v197 systemd/udev will automatically assign predictable, stable network interface names for all local Ethernet, WLAN and WWAN interfaces. This is a departure from the traditional interface naming scheme ("eth0", "eth1", "wlan0", ...), but should fix real problems.

With systemd 197 we have added native support for a number of different naming policies into systemd/udevd proper and made a scheme similar to biosdevname's (but generally more powerful, and closer to kernel-internal device identification schemes) the default. The following different naming schemes for network interfaces are now supported by udev natively:

  1. Names incorporating Firmware/BIOS provided index numbers for on-board devices (example: eno1)
  2. Names incorporating Firmware/BIOS provided PCI Express hotplug slot index numbers (example: ens1)
  3. Names incorporating physical/geographical location of the connector of the hardware (example: enp2s0)
  4. Names incorporating the interfaces's MAC address (example: enx78e7d1ea46da)
  5. Classic, unpredictable kernel-native ethX naming (example: eth0)

By default, systemd v197 will now name interfaces following policy 1) if that information from the firmware is applicable and available, falling back to 2) if that information from the firmware is applicable and available, falling back to 3) if applicable, falling back to 5) in all other cases. Policy 4) is not used by default, but is available if the user chooses so.

This combined policy is only applied as last resort. That means, if the system has biosdevname installed, it will take precedence. If the user has added udev rules which change the name of the kernel devices these will take precedence too. Also, any distribution specific naming schemes generally take precedence.

The naming convention is documented in detail in a comment block for source code file: "udev-builtin-net_id.c". Please refer to document in case you are wondering how to decode the new interface names.

Ways To Alter The Network Interface Names

You basically have four options:

  1. You disable the assignment of fixed names, so that the unpredictable kernel names are used again. For this, simply mask udev's rule file for the default policy: ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules
  2. You create your own manual naming scheme, for example by naming your interfaces "internet0", "dmz0" or "lan0". For that create your own udev rules file and set the NAME property for the devices. Make sure to order it before the default policy file, for example by naming it /etc/udev/rules.d/70-my-net-names.rules
  3. You alter the default policy file, for picking a different naming scheme, for example for naming all interface names after their MAC address by default: cp /usr/lib/udev/rules.d/80-net-name-slot.rules /etc/udev/rules.d/80-net-name-slot.rules, then edit the file there and change the lines as necessary.
  4. You pass the net.ifnames=0 on the kernel command line (since v199)

Example: Want to Shorten the Network Interface Name: eno16777736 To enso1

Here is an example on how to change the network interface name: "eno16777736" to "ens1".

Before Interface Name Change:

[root@localhost network-scripts]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:d2:af:fc brd ff:ff:ff:ff:ff:ff
    inet 10.222.222.116/24 brd 10.222.222.255 scope global dynamic eno1
       valid_lft 54243sec preferred_lft 54243sec
    inet6 fe80::20c:29ff:fed2:affc/64 scope link 
       valid_lft forever preferred_lft forever

We will use the Bus position as the key to identify the network interface name to change for the udev rule. Here is a way to find the Bus position:

for dir in /sys/class/net/* ; do
  [ -e $dir/device ] && {
    basename $dir ; readlink -f $dir/device
  }
done
eno16777736
/sys/devices/pci0000:00/0000:00:15.0/0000:03:00.0