Linux Network Configuration Summary

Source: Internet
Author: User

The IP configuration of Linux is mainly divided into these parts

IP configuration, routing configuration, network management tools


IP configuration

View IP configuration information

Ifconfig: View all active network interfaces

Ifconfig-a: View all active and inactive network interfaces

Ipconfig interface: View specified interface information

[[email protected] ~]# ifconfig eth0eth0      link  encap:ethernet  hwaddr 00:0c:29:06:5b:59             inet addr:192.168.16.208  bcast:192.168.16.255  mask:255.255.255.0           inet6 addr: fe80::20c:29ff:fe06:5b59/64  scope:link          up broadcast running  MULTICAST  MTU:1500  Metric:1           RX packets:224 errors:0 dropped:0 overruns:0 frame:0           TX packets:141 errors:0 dropped:0 overruns:0  carrier:0          collisions:0 txqueuelen:1000            rx bytes:19829  (19.3 kib)   TX bytes:18047  ( 17.6 kib)


Enabling and disabling interfaces

Close interface: Ifdown interface

Open Interface: IFUP interface


Configure IP Address

Ipconfig interface specifies the address, the configuration of the specified address has two formats, 1 address netmask Mask 2. Address/Mask

[[email protected] ~]# ifconfig eth0 192.168.16.209 netmask 255.255.255.0# First configuration [[email protected] ~]# ifconfig eth0 192.16 The second configuration of the 8.16.208/24#

However, the above configuration method is only valid when the system or service is restarted, if the configuration is permanently valid, you need to modify the network interface corresponding configuration file/etc/sysconfig/network-scripts/ifcfg-interface name

The following is the current host ETH interface configuration Document Information/etc/sysconfig/network-scripts/ifcfg-eth0

[[email protected] ~]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0device=eth0 profile associated device, to be consistent with ifcfg-name after hwaddr=00:0c : 29:06:5b:59 interface Mac can have no Type=ethernet interface type uuid=240d5656-bea9-4ea8-acd4-b1bcd715b724 The unique ID number of the interface device Onboot=yes Whether the boot automatically activates the interface Nm_controlled=yes NetworkManager You can configure this interface bootproto=static interface gets the IP type can be DHCP, static, noneipaddr= 192.168.16.208 IP address netmask=255.255.255.0 subnet mask gateway=192.168.16.2 Gateway dns1=8.8.8.8 DNS, up to 3, DNS1, DNS2, Dns3ipv6init =no whether the V6 protocol is allowed to allow a normal user to configure this interface userctl=no when the DHCP service is turned on, whether the interface DHCP configures DNS, that is, modify the/etc/resolv.conf file

After you modify this file, you need to restart the system or service (services network restart, systemctl restart Network) to make it effective.


Single interface configuration multiple IP, need to add multiple virtual interfaces on the physical interface, the virtual interface has a fixed format, such as Eth0 virtual interface is eth0:0, eth0:1, Eth0:2 and so on.

Virtual interface temporarily in effect

Ifconfig Virtual Interface Network address

[[email protected] ~]# ifconfig eth0:2 192.168.16.211/24[[email protected] ~]# ping 192.168.16.211PING 192.168.16.211 (19 2.168.16.211) bytes of data.64 bytes from 192.168.16.211:icmp_seq=1 ttl=64 time=0.021 ms

Permanently valid requires creating a new configuration file, and then adding all parameters manually. As the above example, you need to create the interface/etc/sysconfig/network-scripts/ifcfg-eth0:2, the first line in the configuration file Device=eth0:2, others can be configured as needed



Routing configuration

Viewing routing information

The role of route or Route-n,-N, is to not require a DNS inverse solution, preferably coupled with a faster speed.

[Email protected] ~]# route-nkernel IP routing tabledestination Gateway genmask Flags Metric Ref         Use Iface0.0.0.0 192.168.16.2 0.0.0.0 UG 0 0 eno16777736192.168.16.0 0.0.0.0 255.255.255.0 U 0 0 eno16777736d

Destination: Destination Address, 0.0.0.0 represents arbitrary address, that is, this line is gateway information

Gateway address, 0.0.0.0 means no gateway, that is, this line is the local network address, do not need to walk the gateway

Genmask: Subnet mask for destination address

Flags: identifier, U:UP, G: Gateway, H: Host route

Metric: Priority

Iface: Interface through


Add Host route

Route Add-host Target host address GW through Gateway Dev via interface, if only one interface dev can omit

[[email protected] ~]# route add -host 10.1.1.1 gw 192.168.16.100  dev eno16777736[[email protected] ~]# route -nKernel IP routing  tabledestination     gateway          genmask         flags metric ref     Use Iface0.0.0.0         192.168.16.2     0.0.0.0         UG    100     0        0 eno1677773610.1.1.1         192.168.16.100  255.255.255.255 ugh   0       0        0  Eno16777736192.168.16.0    0.0.0.0         255.255.255.0   u      100    0        0 eno16777736

Adding network routes

Route Add-net Network address GW via Gateway Dev via interface

[[email protected] ~]# route add -net 10.2.0.0/16 gw 192.168.16.101[[ email protected] ~]# route -nkernel ip routing tabledestination      Gateway         Genmask          Flags Metric Ref    Use Iface0.0.0.0          192.168.16.2    0.0.0.0          UG    100    0         0 eno1677773610.1.1.1         192.168.16.100  255.255.255.255 ugh   0      0         0 eno1677773610.2.0.0         192.168.16.101  255.255.0.0     ug    0       0        0 eno16777736192.168.16.0     0.0.0.0         255.255.255.0   u      100    0        0  eno16777736

Add a Gateway

The route add default GW gateway or route add-net 0.0.0.0 GW Gateway, if the existing gateway needs to be deleted before the original.

[[email protected] ~]# route add default GW 192.168.16.112


Removing host routes

Route Del-host Host IP

Remove Network routes

Route Del-net Subnet Address

Remove Gateway

Rounte del-net 0.0.0.0 or route del default gateway Gateway

[Email protected] ~]# route del default GW 192.168.16.2


If the Yao Lu is permanently valid by the information, you need to create the file in/etc/sysconfig/network-scripts/under the corresponding interface, format: route-interface name, for example, Route-eth0

Configuration file format, one line at a route,

Destination address via Next

[Email protected] network-scripts]# Cat/etc/sysconfig/network-scripts/route-eth0 10.0.0.0/ 8via192.168.16.2010.0.0.1via192.168.16.21


Several network management tools

Ping:

-C #: Specify the number of messages sent

-W #: Specifies how long a ping command executes, regardless of the number of messages sent, in seconds

-W #: Waits for a message to return the length of time, in seconds

[Email protected] ~]# ping-c 1-w 1 192.168.16.16PING 192.168.16.16 (192.168.16.16) bytes of data.---192.168.16. Ping Statistics---1 packets transmitted, 0 received, 100% packet loss, time 0ms[[email protected] ~]# ping-c 1-w 1 1  92.168.16.2PING 192.168.16.2 (192.168.16.2) bytes of data.64 bytes from 192.168.16.2:icmp_seq=1 ttl=128 time=0.358 Ms sends a message, regardless of success or not after 1 seconds to return the result

traceroute: Queries all gateways that go through to the destination address


tranceroute Destination IP

Displays a


Netstat Displaying network status information

-T:TCP session

-U:UDP session

-N: Number format display

-L: Listening status

-A: All status, monitoring and non-listening status

-P: Session process and program number

-R: Routing table

#显示左右监听进程 [[email protected] ~]# netstat -tlnactive internet connections  ( Only servers) proto recv-q send-q local address            foreign address         state       tcp        0       0 0.0.0.0:22               0.0.0.0:*                LISTEN     tcp        0       0 127.0.0.1:25             0.0.0.0:*                Listen     tcp6       0      0 :::22                    :::*                      LISTEN     tcp6       0       0 ::1:25                   :::*                      listen

Linux Network Configuration summary

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.