Getting started with Linux Network Configuration

Source: Internet
Author: User

(I) Network Interface

① Naming rules
The Linux kernel specifies a different prefix for the interface name based on the interface type. After the prefix, a number is assigned to each interface from scratch.
For example:
All Ethernet interfaces start with ETH. eth0, eth1, and eth2 indicate the first, second, and third Ethernet cards respectively.
② Display Nic configuration information
Only active NICs are displayed.
Ifconfig

Display All interfaces (network interfaces)
Ifconfig-
Or
IP Link

(Ii) Driver selection

RedHat compiles the NIC driver into a kernel module. According to the configuration in/etc/modprobe. conf, the NIC module is loaded at boot time.
Map the interface name to the specified module in/etc/modprobe. conf.

[root@Think ~]# grep 'alias eth' /etc/modprobe.confalias eth0 vmxnetalias eth1 e1000alias eth2 e1000

If there is only one Nic, that is, only one Nic uses this module (driver), you can configure it in modprobe. conf.
If multiple NICs map to one module at the same time, for example, in the preceding example, if both eth1 and eth2 use the e1000 module, you must specify hwaddr.
You can specify the hwaddr variable in/etc/sysconfig/network-scripts/ifcfg-eth *.

[root@Think ~]# grep 'HWADDR' /etc/sysconfig/network-scripts/ifcfg-eth*/etc/sysconfig/network-scripts/ifcfg-eth1:HWADDR=00:C2:89:fQ:b7:55/etc/sysconfig/network-scripts/ifcfg-eth2:HWADDR=00:TC:Q6:CC:5F:F5

(Iii) bandwidth and duplex settings

In the default mode, the interface module is configured as autonegotiate, which allows the NIC to communicate with the upper-level hub/switch and selects the best setting.
But sometimes it is not optimal. We can set it manually.
① Temporary modification:
Ifdown eth0
Ethtool-s eth0 autoneg off speed 1000 duplex full
IFUP eth0
Set the network adapter eth0 to 1000 Mbps in full duplex mode, and disable automatic negotiation.
② Permanent modification:
You only need to add the ethtool_opts variable to/etc/sysconfig/network-scripts/ifcfg-ethx:
Ethtool_opts = "autoneg off speed 1000 duplex full"

(Iv) Dynamic IPv4 Configuration

The interface configuration is defined in:
/Etc/sysconfig/network-scripts/ifcfg-etcx
Dynamic Setting using variable: bootproto = DHCP
Case:

[root@Think ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0BOOTPROTO=dhcpONBOOT=yes

Activate configuration changes:
Ifdown ethx
IFUP ethx

(V) Static IPv4 Configuration

The interface configuration is defined in:
/Etc/sysconfig/network-scripts/ifcfg-etcx
Static configuration variable: bootproto = none
Ipaddr =
Netmask =
Case:

[root@Think ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0DEVICE=eth0BOOTPROTO=noneIPADDR=192.168.1.112NETMASK=255.255.255.0GATEWAY=192.168.1.1ONBOOT=yes

Activate configuration changes:
Ifdown ethx
IFUP ethx

(Vi) IP alias

Bind multiple IP addresses to one network card
For example:
Eth0: 1
Eth0: 2
Eth0: 3
An independent interface configuration file is generated for each device alias.
For example:/etc/sysconfig/network-scripts/ifcfg-etc0: 1
For specific configuration, refer to the previous blog: http://blog.csdn.net/linwaterbin/article/details/8214538

(Vii) route table

To browse the route table, use:
Route
Netstat-R
IP Route

[root@Think ~]# routeKernel IP routing tableDestination     Gateway         Genmask         Flags Metric Ref    Use Iface192.168.1.0     *               255.255.255.0   U     0      0        0 eth0192.168.122.0   *               255.255.255.0   U     0      0        0 virbr0169.254.0.0     *               255.255.0.0     U     0      0        0 eth0default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0[root@Think ~]# netstat -rKernel IP routing tableDestination     Gateway         Genmask         Flags   MSS Window  irtt Iface192.168.1.0     *               255.255.255.0   U         0 0          0 eth0192.168.122.0   *               255.255.255.0   U         0 0          0 virbr0169.254.0.0     *               255.255.0.0     U         0 0          0 eth0default         192.168.1.1     0.0.0.0         UG        0 0          0 eth0[root@Think ~]# ip route192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.112 192.168.122.0/24 dev virbr0  proto kernel  scope link  src 192.168.122.1 169.254.0.0/16 dev eth0  scope link default via 192.168.1.1 dev eth0 

㈧ Default Gateway

When no "more specific matching" exists in the routing table, the default gateway (that is, the router) decides where to send the IP packet
This function is usually used when the LAN has only one egress.
Dynamic retrieval: configure the DHCP server
Static configuration: Use the variable Gateway
Configure in the general network configuration file
/Etc/sysconfig/Network
Configure in the interface configuration file
/Etc/sysconfig/network-scripts/ifcfg-ethx
If both common and interface configurations are performed, the interface configuration has a higher priority.

㈨ Determine IP connectivity

Ping: a measurement tool for network packet loss and wait time
By default, Ping sends a 64 byte ICMP packet to the specified host per second.
-C option allows the number of ICMP packets that should be sent when Ctrl-C is used to cancel the ping command.
Traceroute: displays the network path to the destination.
The traffic goes through multiple routers. It is usually useful to determine which router has a fault.

(10) define the local host name

Query Host Name: Hostname
Temporary definition: Hostname think
Permanent definition: Specify the hostname variable in/etc/sysconfig/Network

(11) Local Parsing

Higher than DNS
Configuration file/etc/hosts
The localhost entry must be included, and it is better to include the host name already defined in/etc/sysconfig/network.
Do not modify the localhost line, but you can add an alias in the last part of the line.

[root@Think ~]# cat /etc/hosts# Do not remove the following line, or various programs# that require network functionality will fail.127.0.0.1               localhost.localdomain localhost192.168.1.112  localhost.localdomain  localhost117.79.93.222  www.csdn.net www

(12) Remote resolution

Configuration file/etc/resolv. conf
For more DNS information, see the previous blog:
Http://blog.csdn.net/linwaterbin/article/details/8228177

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.