Linux Network Configuration-2
Nov. 20th, 2015 05:05 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Red Hat / Fedora / CentOS IP Configuration Files:
To disable DHCP change BOOTPROTO=dhcp to BOOTPROTO=none
Forwarding allows the network packets on one network interface (i.e. eth0) to be forwarded to another network interface (i.e. eth1). This will allow the Linux computer to connect ("ethernet bridge") or route network traffic.
http://www.yolinux.com/TUTORIALS/LinuxTutorialNetworking.html
The Red Hat configuration tools store the configuration information in the file /etc/sysconfig/network.
They will also allow one to configure routing information.
They will also allow one to configure routing information.
- File: /etc/sysconfig/network Static IP address Configuration: (Configure gateway address)
NETWORKING=yes HOSTNAME=my-hostname - Hostname is defined here and by command hostname FORWARD_IPV4=true - True for NAT firewall gateways and linux routers. False for everyone else - desktops and servers. GATEWAY="XXX.XXX.XXX.YYY" - Used if your network is connected to another network or the internet. Static IP configuration. Gateway not defined here for DHCP client.
NETWORKING=yes HOSTNAME=my-hostname - Hostname is defined here and by command hostname
NETWORKING=yes HOSTNAME=my-hostname - Hostname is defined here and by command hostname NISDOMAIN=NISProject1 - NIS domain to attach
- File (Red Hat/Fedora): /etc/sysconfig/network-scripts/ifcfg-eth0
(S.u.s.e.: /etc/sysconfig/network/ifcfg-eth-id-XX:XX:XX:XX:XX)
This file used by the command scripts ifup and ifdownStatic IP address configuration:DEVICE=eth0 BOOTPROTO=static BROADCAST=XXX.XXX.XXX.255 IPADDR=XXX.XXX.XXX.XXX NETMASK=255.255.255.0 NETWORK=XXX.XXX.XXX.0 ONBOOT=yes - Will activate upon system boot
- TYPE=Ethernet
- HWADDR=XX:XX:XX:XX:XX:XX
- GATEWAY=XXX.XXX.XXX.XXX
OR for DHCP client configuration:DEVICE=eth0 ONBOOT=yes BOOTPROTO=dhcp
- IPV6INIT=no
- USERCTL=no
- PEERDNS=yes
- TYPE=Ethernet
- HWADDR=XX:XX:XX:XX:XX:XX
To disable DHCP change BOOTPROTO=dhcp to BOOTPROTO=none
In order for updated information in any of these files to take effect, one must issue the command: service network restart (or: /etc/init.d/network restart)
Network IP aliasing: |
Assign more than one IP address to one ethernet card:
ifconfig eth0 XXX.XXX.XXX.XXX netmask 255.255.255.0 broadcast XXX.XXX.XXX.255 ifconfig eth0:0 192.168.10.12 netmask 255.255.255.0 broadcast 192.168.10.255 ifconfig eth0:1 192.168.10.14 netmask 255.255.255.0 broadcast 192.168.10.255 route add -host XXX.XXX.XXX.XXX dev eth0 route add -host 192.168.10.12 dev eth0 route add -host 192.168.10.14 dev eth0
eth0 Link encap:Ethernet HWaddr 00:10:4C:25:7A:3F inet addr:XXX.XXX.XXX.XXX Bcast:XXX.XXX.XXX.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14218 errors:0 dropped:0 overruns:0 frame:0 TX packets:1362 errors:0 dropped:0 overruns:0 carrier:0 collisions:1 txqueuelen:100 Interrupt:5 Base address:0xe400 eth0:0 Link encap:Ethernet HWaddr 00:10:4C:25:7A:3F inet addr:192.168.10.12 Bcast:192.168.10.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:5 Base address:0xe400 eth0:1 Link encap:Ethernet HWaddr 00:10:4C:25:7A:3F inet addr:192.168.10.14 Bcast:192.168.10.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:5 Base address:0xe400
Config file: /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0 ONBOOT=yes BOOTPROTO=static BROADCAST=192.168.10.255 IPADDR=192.168.10.12 NETMASK=255.255.255.0 NETWORK=192.168.10.0 ONBOOT=yes
The option during kernel compile is: CONFIG_IP_ALIAS=y (Enabled by default in Redhat)
Note: The Apache web server can be configured so that different IP addresses can be assigned to specific domains being hosted. See Apache configuration and "configuring an IP based virtual host" in the YoLinux Web site configuration tutorial.
DHCP Linux Client: get connection info: /sbin/pump -i eth0 --status
(Red Hat Linux 7.1 and older)
(Red Hat Linux 7.1 and older)
-
Device eth0 IP: 4.XXX.XXX.XXX Netmask: 255.255.252.0 Broadcast: 4.XXX.XXX.255 Network: 4.XXX.XXX.0 server 131.XXX.XXX.4 Next server 0.0.0.0 Gateway: 4.XXX.XXX.1 Domain: vz.dsl.genuity.net Nameservers: 4.XXX.XXX.1 4.XXX.XXX.2 4.XXX.XXX.3 Renewal time: Sat Aug 11 08:28:55 2001 Expiration time: Sat Aug 11 11:28:55 2001
Changing the host name: |
This is a three step process:
- Issue the command: hostname new-host-name
- Change network configuration file: /etc/sysconfig/network
Edit entry: HOSTNAME=new-host-name - Restart systems which relied on the hostname (or reboot):
- Restart network services: service network restart
(or: /etc/init.d/network restart) - Restart desktop:
- Bring down system to console mode: init 3
- Bring up X-Windows: init 5
- Restart network services: service network restart
Note that hostnames may only contain alphanumeric characters, minus signs ("-"), and periods ("."). They must begin with an alphabetic character and end with an alphanumeric character.
Change the host name using GUI tool: /usr/sbin/system-config-network
(Red Hat / Fedora / CentOS)
(Red Hat / Fedora / CentOS)
Hostname entries are made in two places:
![]() | ![]() |
Select the "DNS" tab. | Select the "Devices" tab + "Edit" + the "General" tab. |
Activating and De-Activating your NIC: |
Commands for starting and stopping TCP/IP network services on a Network Interface Card (NIC):
files in /etc/sysconfig/network-scripts/ GUI Interface control/configuration:
| ![]() |
Subnets: |
Subnetting is a methodology used to divide a network into multiple logical networks (subnets). Subnets are often defined for geographical or location reasons. Subnet masks are defined to reflect the number of computer systems and the IP addresses of the systems on the subnet.
M A S K | # OF SUB NETS | Slash Fmt | CLASS A HOSTS | CLASS A MASK | CLASS B HOSTS | CLASS B MASK | CLASS C HOSTS | CLASS C MASK | CLASS C SUB HOSTS | CLASS C SUB MASK |
---|---|---|---|---|---|---|---|---|---|---|
255 | 1 or 256 | /32 | 16,777,214 | 255.0.0.0 | 65,534 | 255.255.0.0 | 254 | 255.255.255.0 | Invalid 1 address | 255.255.255.255 |
254 | 128 | /31 | 33,554,430 | 254.0.0.0 | 131,070 | 255.254.0.0 | 510 | 255.255.254.0 | Invalid 2 addresses | 255.255.255.254 |
252 | 64 | /30 | 67,108,862 | 252.0.0.0 | 262,142 | 255.252.0.0 | 1,022 | 255.255.252.0 | 2 hosts 4 addresses | 255.255.255.252 |
248 | 32 | /29 | 134,217,726 | 248.0.0.0 | 524,286 | 255.248.0.0 | 2,046 | 255.255.248.0 | 6 hosts 8 addresses | 255.255.255.248 |
240 | 16 | /28 | 268,435,454 | 240.0.0.0 | 1,048,574 | 255.240.0.0 | 4,094 | 255.255.240.0 | 14 hosts 16 addresses | 255.255.255.240 |
224 | 8 | /27 | 536,870,910 | 224.0.0.0 | 2,097,150 | 255.224.0.0 | 8,190 | 255.255.224.0 | 30 hosts 32 addresses | 255.255.255.224 |
192 | 4 | /26 | 1,073,741,822 | 192.0.0.0 | 4,194,302 | 255.192.0.0 | 16,382 | 255.255.192.0 | 62 hosts 64 addresses | 255.255.255.192 |
128 | 2 | /25 | 2,147,483,646 | 128.0.0.0 | 8,388,606 | 255.128.0.0 | 32,766 | 255.255.128.0 | 126 hosts 128 addresses | 255.255.255.128 |
Binary position | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Example: 192 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
Example 192=128+64
Some addresses are reserved and outside this scope. Loopback (127.0.0.1), reserved class C 192.168.XXX.XXX, reserved class B 172.31.XXX.XXX and reserved class A 10.XXX.XXX.XXX.
Subnet Example:
- Your ISP assigns you a subnet mask of 255.255.255.248 for your office.
- 208.88.34.104 Network Base address
- 208.88.34.105 Computer 1
- 208.88.34.106 Computer 2
- 208.88.34.107 Computer 3
- 208.88.34.108 Computer 4
- 208.88.34.109 Computer 5
- 208.88.34.110 DSL router/Gateway
- 208.88.34.111 Broadcast address
Links:
Network Classes: |
The concept of network classes is a little obsolete as subnets are now used to define smaller networks using CIDR (Classless Inter-Domain Routing) as detailed above. These subnets may be part of a class A, B, C, etc network. For historical reference the network classes are defined as follows:
- Class A: Defined by the first 8 bits with a range of 0 - 127.
First number (8 bits) is defined by Internic i.e. 77.XXX.XXX.XXX
One class A network can define 16,777,214 hosts.
Range: 0.0.0.0 - 127.255.255.255 - Class B: Defined by the first 8 bits with a range from 128 - 191
First two numbers (16 bits) are defined by Internic i.e. 182.56.XXX.XXX
One class B network can define 65,534 hosts.
Range: 128.0.0.0 - 191.255.255.255 - Class C: Defined by the first 8 bits with a range from 192 - 223
First three numbers (24 bits) are defined by Internic i.e. 220.56.222.XXX
One class B network can define 254 hosts.
Range: 192.0.0.0 - 223.255.255.255 - Class D: Defined by the first 8 bits with a range from 224 - 239
This is reserved for multicast networks (RFC988)
Range: 224.0.0.0 - 239.255.255.255 - Class E: Defined by the first 8 bits with a range from 240 - 255
This is reserved for experimental use.
Range: 240.0.0.0 - 247.255.255.255
Enable Forwarding: |
The bridge configuration will merge two (or several) networks into one single network topology. IpTables firewall rules can be used to filter traffic.
A router configuration can support multicast and basic IP routing using the "route" command. IP masquerading (NAT) can be used to connect private local area networks (LAN) to the internet or load balance servers.
- Turn on IP forwarding to allow Linux computer to act as a gateway or router.
echo 1 > /proc/sys/net/ipv4/ip_forward
Default is 0. One can add firewall rules by using ipchains.Another method is to alter the Linux kernel config file: /etc/sysctl.conf Set the following value:net.ipv4.ip_forward = 1
See file /etc/sysconfig/network for storing this configuration.FORWARD_IPV4=true
All methods will result in a proc file value of "1". Test: cat /proc/sys/net/ipv4/ip_forward
The TCP Man page - Linux Programmer's Manual and /usr/src/linux/Documentation/proc.txt (Kernel 2.2 RH 7.0-) cover /proc/sys/net/ipv4/* file descriptions.
Also see: (YoLinux tutorials)
- Configure Linux as an internet gateway router: Using Linux and iptables/ipchains to set up an internet gateway for home or office (iptables)
- Load balancing servers using LVS (Linux Virtual Server) (ipvsadm)
Adding a network interface card (NIC): |
Manual method: This does not alter the permanent configuration and will only configure support until the next reboot.
- cd /lib/modules/2.2.5-15/net/ - Use kernel version for your system. This example uses 2.2.5-15
(Fedora Core 3: /lib/modules/2.6.12-1.1381_FC3/kernel/net/)
Here you will find the modules supported by your system.
It can be permanently added to:- /etc/modprobe.conf (kernel 2.6)
- /etc/modules.conf (kernel 2.4)
- (or for older systems: /etc/conf.modules)
alias eth0 3c59x
- /sbin/insmod 3c59x (For a 3Com ethernet card)
This inserts the specified module into the kernel. - /sbin/modprobe 3c59x
This also loads a module into the system kernel.
Modprobe command line options:- -r : to unload the module.
- /sbin/modprobe -l \* : list all modules.
- /sbin/modprobe -lt net \* : List only network modules
- /sbin/modprobe -t net \* : Try loading all network modules and see what sticks. (act of desperation)
- ifconfig ...
The easy way: Red Hat versions 6.2 and later, ship with Kudzu, a device detection program which runs during system initialization. (/etc/rc.d/init.d/kudzu) This can detect a newly installed NIC and load the appropriate driver. Then use /usr/sbin/netconfig to configure the IP address and network settings. The configuration will be stored so that it will be utilized upon system boot.
Systems with two NIC cards: Typically two cards are used when connecting to two networks. In this case the device must be defined using one of three methods:
- Use the Red Hat GUI tool /usr/bin/netcfg OR
- Define network parameters in configuration files: Define new device in file (Red Hat/Fedora) /etc/sysconfig/network-scripts/ifcfg-eth1
(S.u.s.e 9.2: /etc/sysconfig/network/ifcfg-eth-id-XX:XX:XX:XX:XX)DEVICE=eth1 BOOTPROTO=static IPADDR=192.168.10.12 NETMASK=255.255.255.0 GATEWAY=XXX.XXX.XXX.XXX HOSTNAME=node-name.name-of-domain.com DOMAIN=name-of-domain.com
(Red Hat/Fedora): /etc/sysconfig/static-routes
(S.u.s.e. 9.2: /etc/sysconfig/network/routes)Example:eth1 net XXX.XXX.XXX.0 netmask 255.255.255.0 gw XXX.XXX.XXX.XXX
OR - Define network parameters using Unix command line interface: Define IP address:
ifconfig eth0 XXX.XXX.XXX.XXX netmask 255.255.255.0 broadcast XXX.XXX.XXX.255 ifconfig eth1 192.168.10.12 netmask 255.255.255.0 broadcast 192.168.10.255
route add default gw XXX.XXX.XXX.XXX dev eth0 route add -net XXX.XXX.XXX.0 netmask 255.255.255.0 gw XXX.XXX.XXX.XXX dev eth0
Where XXX.XXX.XXX.XXX is the gateway to the internet as defined by your ISP or network operator.If a mistake is made just repeat the route command substituting "del" in place of "add".
Configuring your NIC: Speed and Duplex settings: |
This is usually not necessary because most ethernet adapters can auto-negotiate link speed and duplex setting.
- List NIC speed and configuration: mii-tool
eth0: negotiated 100baseTx-FD flow-control, link okVerbose mode: mii-tool -veth0: negotiated 100baseTx-FD flow-control, link ok product info: Intel 82555 rev 4 basic mode: autonegotiation enabled basic status: autonegotiation complete, link ok capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
- Set NIC configuration: mii-tool -F option
Option Parameters -F 100baseTx-FD
100baseTx-HD
10baseT-FD
10baseT-HD-A 100baseT4
100baseTx-FD
100baseTx-HD
10baseT-FD
10baseT-HD
- Query NIC with ethtool:
Command Description ethtool -g eth0 Queries ethernet device for rx/tx ring parameter information. ethtool -a eth0 Queries ethernet device for pause parameter information. ethtool -c eth0 Queries ethernet device for coalescing information. ethtool -i eth0 Queries ethernet device for associated driver information. ethtool -d eth0 Prints a register dump for the specified ethernet device. ethtool -k eth0 Queries ethernet device for offload information. ethtool -S eth0 Queries ethernet device for NIC and driver statistics.
Man Pages:
- mii-tool - view, manipulate media-independent interface status
- ethtool - Display or change ethernet card settings
Route: |
The Linux OS manages outbound and inbound IP (Internet Protocol) traffic. Inbound traffic is captured based on ARP and IP address configuration. Outbound traffic is managed by routes. Routing determines the path these packets take so that they are sent to their destinations. This is required for all IP traffic, local and remote, including when multiple network interfaces are available. Routes are held by the kernel routing table.
Direct routing table entries occur when the source and destination hosts are on the same physical network and packets are sent directly from the source to the destination.
Indirect routing table entries occur when the source and destination hosts are on different physical networks. The destination host must be reached through one or more IP gateways. The first gateway is the only one which is known by the host system.
Default routing defines a gateway to use when the direct network route and the indirect host routes are not defined for a given IP address.
Static routes: IP uses a routing table to determine where packets should be sent. First the packet is examined to see if its' destination is for the local or remote network. If it is to be sent to a remote network, the routing table is consulted to determine the path. If there is no information in the routing table then the packet is sent to the default gateway. Static routes are set with the route command and with the configuration file:
- Red Hat/Fedora: /etc/sysconfig/network-scripts/route-eth0
- Red Hat 7: /etc/sysconfig/static-routes
- S.u.s.e. 9.2: /etc/sysconfig/network/routes
10.2.3.0/16 via 192.168.10.254
Dynamic routes: RIP (Routing Information Protocol) is used to define dynamic routes. If multiple routes are possible, RIP will choose the shortest route. (Fewest hops between routers not physical distance.) Routers use RIP to broadcast the routing table over UDP port 520. The routers would then add new or improved routes to their routing tables.
Man pages:
- route - show / manipulate the IP routing table (Static route)
- Show routes:
Option Description -n display IP addresses. Do not resolve host names for faster results. -e Print more extensive information about routes. -v Verbose. --help Route command information. Option Description add or del or neither Add or delete route information. If not specified then print route table information. -host XXX.XXX.XXX.XXX Add a single computer host identified by the IP address. -net XXX.XXX.XXX.XXX Add a network identified by the network address, to the route. gw XXX.XXX.XXX.XXX Specify the network gateway. netmask XXX.XXX.XXX.XXX Specify the network netmask. default Of all the routes specified, identify one as the default network route.
(typically the gateway is specified as the default route)
- Show routing table: route -e
- Access individual computer host specified via network interface card eth1:
route add -host 123.213.221.231 eth1 - Access ISP network identified by the network address and netmask using network interface card eth0:
route add -net 10.13.21.0 netmask 255.255.255.0 gw 192.168.10.254 eth0
Conversely: route del -net 10.13.21.0 netmask 255.255.255.0 gw 192.168.10.254 eth0 - Specify default gateway to use to access remote network via network interface card eth0:
route add default gw 201.51.31.1 eth0
(Gateway can also be defined in /etc/sysconfig/network) - Specify two gateways for two network destinations: (i.e. one external, one internal private network. Two routers/gateways will be specified.)
Add internet gateway as before: route add default gw 201.51.31.1 eth0
Add second private network: route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.10.254 eth0
- Show routes:
- routed - network routing daemon. Uses RIP protocol to update routing table.
- ipx_route - show / manipulate the IPX routing table - IPX is the Novell networking protocol (Not typically used unless your office has Novell servers)
- ifuser - Identify destinations routed to a particular network interface.
VPN, Tunneling: |
- Commercial VPN Linux software solutions - YoLinux
- OpenSWAN.org - IPSec VPN for Linux
- strongSwan.org - IPSec VPN for Linux (follow-on to FreeSWAN)
- FreeSWAN tutorial - howto
- OpenVPN - SSL VPN solution for site to site, WiFi security, and enterprise-scale remote access with load balancing, failover, and fine-grained access-controls.
- SSL-Explorer - Java SLL based VPN
- Quagga dynamic routing suite VLAN
- NTop: n2n pier to pier within a private fabric
- CIPE: Crypto IP Encapsulation (Easiest way to configure two Linux gateways connecting two private networks over the internet with encryption.)
- CIPE Home page - CIPE is a simple encapsulation system that securely connects two subnets.
- VPN HowTo - Matthew D. Wilson
- Installing and Running PPTP on Linux
- L2TP Extensions (l2tpext) Internet Drafts.
Useful Linux networking commands: |
- /etc/rc.d/init.d/network start - command to start, restart or stop the network
- netstat - Display connections, routing tables, stats etc
- List externally connected processes: netstat -punta
- -a: Show both listening and non-listening sockets.
- -p: Show PID of process owning socket
- -u: Show UDP
- -t: Show TCP
- -n: Show IP addresses only. Don't resolve host names
- -g: Show multi-cast group membership info
- -c: Continuous mode - update info every second
- -v: Verbose
- -e: Extended information
- -o: show network timer information
- List all connected processes: netstat -nap
- Show network statistics: netstat -s
- Display routing table info: netstat -rn
$ netstat -nr Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
- G: route uses gateway
- U: Interface is "up"
- H: Only a single host is accessible (eg. loopback)
- D: Entry generated by ICMP redirect message
- M: Modified by ICMP redirect message
- Display interface statistics: netstat -i
$ netstat -i Kernel Interface table Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg eth0 1500 0 2224 0 0 0 1969 0 0 0 BMRU lo 16436 0 1428 0 0 0 1428 0 0 0 LRU
- RX-OK/TX-OK: number of packets transmitted/received error free
- RX-ERR/TX-ERR: number of damaged/error packets transmitted/received
- RX-DRP/TX-DRP: number of dropped packets
- RX-OVR/TX-OVR: number of packets dropped because of a buffer overrun
- B: A broadcast address has been set
- L: This interface is a loopback device
- M: All packets are received
- N: Trailers are avoided
- O: ARP is turned off for this interface
- P: Point-to-point connection
- R: Interface is running
- U: Interface is up
- List externally connected processes: netstat -punta
- rtstat/lnstat - unified linux network statistics
(reports contents of /proc/net/stat/ and routing cache statistics) - nstat/rtacct - network statistics tools
(monitor kernel snmp counters and network interface statistics) - ping - send ICMP ECHO_REQUEST packets to network hosts. Use Cntl-C to stop ping.
- traceroute - print the route packets take to network host.
(Ubuntu Note: Typically Ubuntu installs tracepath for IPv4 and traceroute6 for IPv6. One can install traceroute: apt-get install traceroute)- traceroute IP-address-of-server
- traceroute domain-name-of-server
- mtr - a network diagnostic tool introduced in Fedora - Like traceroute except it gives more network quality and network diagnostic info. Leave running to get real time stats. Reports best and worst round trip times in milliseconds.
- mtr IP-address-of-server
- mtr domain-name-of-server
- whois - Lookup a domain name in the internic whois database.
- finger - Display information on a system user. i.e. finger user@host Uses $HOME/.plan and $HOME/.project user files.
- iptables - IP firewall administration (Linux kernel 2.6/2.4) See YoLinux firewall/gateway configuration.
- ipchains - IP firewall administration (Linux kernel 2.2) See YoLinux firewall/gateway configuration.
- socklist - Display list of open sockets, type, port, process id and the name of the process. Kill with fuser or kill.
- host - Give a host name and the command will return IP address. Unlike nslookup, the host command will use both /etc/hosts as well as DNS.
Example: host domain-name-of-server - nslookup - Give a host name and the command will return IP address. Also see Testing your DNS (YoLinux Tutorial) Note that nslookup does not use the /etc/hosts file.
http://www.yolinux.com/TUTORIALS/LinuxTutorialNetworking.html