Edit a network configuration file

Source: Internet
Author: User

Today I learned the network configuration of Linux.

The first is to check the configuration of the network, you can determine the network interface, network address.

Displays the IP address and subnet mask for all current interfaces
IP addr

You can also display information for a network card, such as the first network card, is eth0

Displays information for the first NIC
Ip-s Link Show eth0

After you find a connection problem, you can use ping to test connectivity

PING-C3 172.25.25.254

For the relevant parameters of the IP command, I looked for a bit on the internet, attached to, such as-s what is the meaning of link what does-C3 mean

IP commands are used to display or manipulate Linux hosts for routing, network devices, Policy routing, and Tunneling, which is a powerful network configuration tool under Linux.

Syntax IP (option) (parameter) options

-V: Displays the instruction version information;

-S: output more detailed information;

-F: Enforces the use of the specified protocol family;

-4: Specifies that the network layer protocol used is the IPV4 protocol;

-6: Specifies that the network layer protocol used is the IPV6 protocol;

-0: Output information each record output one line, even if the content is more than the line display;

-R: When displaying the host, do not use the IP address while using the host's domain name.

-C count is the number,-c3 three ping packets

Link This parameter option is not added before-meaning is the MAC address of the device hardware, why not add-I do not know that the same as show or IP is a command it. That's what I understand.

Parameters

Network object: Specifies the network object to be managed;

Specific operation: To complete the specific operation of the specified network object;

Help: Displays helpful information for the operation commands supported by the network object.

From: HTTP://MAN.LINUXDE.NET/IP

For example, I found this blog to cite examples:

To display the operating status of a network device with an IP command

[[Email protected] ~]# IP Link list

1:lo: <loopback,up,lower_up>mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00

2:eth0: <broadcast,multicast,up,lower_up>mtu qdisc pfifo_fast qlen, link/ether 00:16:3e:00:1e:51 BRD ff:f F:ff:ff:ff:ff

3:eth1: <broadcast,multicast,up,lower_up>mtu qdisc pfifo_fast qlen, link/ether 00:16:3e:00:1e:52 BRD ff:f F:ff:ff:ff:ff

Display more detailed device information

[Email protected] ~]# ip-s link list

1:lo: <loopback,up,lower_up>mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00 rx:byte s packets errors dropped overrun Mcast 5082831 56145 0 0 0 0 tx:bytes packets errors dropped carrier Collsns 5082831 5614 5 0 0) 0 0

2:eth0: <broadcast,multicast,up,lower_up>mtu qdisc pfifo_fast qlen, link/ether 00:16:3e:00:1e:51 BRD ff:f F:FF:FF:FF:FF rx:bytes packets Errors dropped overrun Mcast 3641655380 62027099 0 0 0 0 tx:bytes packets errors dropped Carrier Collsns 6155236 89160 0 0 0 0

3:eth1: <broadcast,multicast,up,lower_up>mtu qdisc pfifo_fast qlen, link/ether 00:16:3e:00:1e:52 BRD ff:f F:FF:FF:FF:FF rx:bytes packets Errors dropped overrun Mcast 2562136822 488237847 0 0 0 0 tx:bytes packets errors dropped Carrier Collsns 3486617396 9691081 0 0 0 0

Show Core routing table

[[Email protected] ~]# IP Route list

112.124.12.0/22 Dev eth1 proto kernel scope link src 112.124.15.130 10.160.0.0/20 dev eth0 proto kernel scope link src 10. 160.7.81 192.168.0.0/16 via 10.160.15.247 dev eth0 172.16.0.0/12 via 10.160.15.247 dev eth0 10.0.0.0/8 via 10.160.15.247 D EV eth0 default via 112.124.15.247 Dev eth1

Show Neighbor Table

[[Email protected] ~]# IP neigh list

112.124.15.247 Dev eth1 lladdr 00:00:0c:9f:f3:88 REACHABLE 10.160.15.247 dev eth0 lladdr 00:00:0c:9f:f2:c0 STALE

From: HTTP://MAN.LINUXDE.NET/IP

The orders of the great Gods can be expressed by formatting, but I don't know how to format them, and they are better to show them legibility. I want to learn a lot of places.

Other in the check network configuration, the use of the command and the big God example, using the IP addr display all interfaces of the current IP and mask, ip-s link show eth0 output the first NIC more detailed information, which contains the device's Mac, from here can see link show As with IP, it is a command. That's what I understand. IP route, which displays routing information. PING-C3 172.25.25.254 sends 3 ping packets to the IP for 172.25.25.254.

There was a strange order, not to say in the book, but to use it directly. I don't know what that means.

That is to show all hops between the local system and the classroom.example.com host, what is a hop? It may be a question of translation. Don't understand. Take a look at this strange command:

$ Tracepath classroom.example.com

Next there is an unnamed command, this is really inexplicable. Say yes to display TCP sockets listening on the Local system: $ ss-lt

Above these 2 commands, do not know what to explain.

Here's where you'll learn to configure your network with NMCLI: Manage network settings and devices using NMCLI and NetworkManager. I thought Nmcli and NetworkManager were 2 orders, but the entire article only saw the use of NMCLI, which is also very confusing.

To view network information, if you want to list only active connections, you can add the--active option after the following command
Nmcli Con Show

Specify a device to view connection information: Nmcli con Show "Static-eth0"

Show Device status and details: Nmcli dev Status

Display specified device status and details: Nmcli Dev show eth0

Here's a form like creating a network connection, using the NMCLI command

The book says: NMCLI When you create a network connection, the order of the parameters is important, first the shared parameters, and the type interface must be included. Next, specify any type-related parameters, and finally specify the IP address prefix and gateway information. It also says that you can specify multiple IPs for a single device. Other settings, such as DNS, can be modified after the connection is established.

Example 1: Define a new connection named "Default", using DHCP to connect automatically via Eth0 network connection with Ethernet, # nmcli con add con-name "default" type Ethernet ifname eth0

Example 2: Establish a connection named "Static", specify IP and gateway, do not connect automatically. # nmcli con add con-name "static" ifname eth0 AutoConnect No type Ethernet IP4 172.25.25.254/24 gw172.25.25.254 This command I can basically read , just do not know what GW means, I do not know where to find, man Nmcli also did not find. What does GW mean, it looks like DNS or something else? /24 means 1 followed by 24 0, the meaning of a mask.

The following is the system when the "automatic connection via DHCP" to a static connection, may be set IP4, activate, even if the static connection, but see some tutorials that the system started effectively, you need to change the configuration file. Don't say it, write this command first. # nmcli con up "static"

Attach the configuration file directory found on the Web:

Network configuration file:
/etc/sysconfig/network said is the global settings, the default is nothing, you can add the global default gateway
/etc/hostname after modifying hostname with NMTUI, the host name is saved here
/etc/resolv.conf Save DNS settings, do not need to manually change, Nmtui inside the set of DNS will appear here
/etc/sysconfig/network-scripts/Connection configuration information ifcfg file
/etc/networkmanager/system-connections/vpn, Mobile Broadband, PPPoE connection

The book also said, and then change back to the DHCP connection: # NMCLI con up "default", this is the above 2 examples of the exercise, learning a bit ignorant. It's so hard to have no foundation.

There is a hint in the book that if a static connection is lost, the default connection is automatically connected. The way to prevent automatic connection is to disable an interface as an administrator: Nmcli dev Disconnect devicename, there are some types of WiFi type, bridge type, you can use NMCLI con add Help to view the type of choice. The above example only uses Ethernet.

Here's another practice scenario:

To modify the network interface via NMCLI:

Used nmcli con mod.

View a list of connections with nmcli con show "[ID]"

For example, see the list of static connections, #nmcli con show "Static"

Example:

Turn off Auto Connect: # nmcli con mod "static" Connection.autoconnect No

Specify DNS server: # nmcli con mod "static" Ipv4.dns 172.25.25.254

The book mentions that you can use +/-to add or remove some configuration parameter values. For example, adding an auxiliary DNS

NMCLI con mod "static" +ipv4.dns 8.8.8.8

Replace static IP and gateways

# nmcli con mod "static" Ipv4.addresses 172.25.25.10/24 172.25.25.254 "This command may be to replace the front of the back, that is, behind the 172.25.25.254 is covered." The book did not write, I in the experiment, tried, also did not make clear.

A secondary IP with no gateway is added later. # nmcli con mod "static" +ipv4.addresses 10.10.10.10/16

Save one, to activate the connection before you can use it. # nmcli con up "static"

The following is a summary of a NMCLI command

NMCLI Dev Status List all devices
Nmcli Con Show List all connections
Nmcli con up "<ID>" Activating the connection
Nmcli con Down "<ID>" Deactivate the connection and if the value is automatically reconnected: Yes, the connection will be restarted. Restart is to reconnect it, that is, to cancel the connection, first ensure that the configuration file value is no, in which file modification do not know, using nmcli con mod "<ID>" Connection.autoconnect no should be OK, I asked Baidu
Nmcli Dev Dis <DEV> Interrupt interface, and temporarily disable automatic connection
Nmcli con off ... Disable all managed interfaces
Nmcli con Add ... Add a new connection
Nmcli con mod "<ID>" ... Modify Connection
Nmcli con del "<ID>" Delete Connection

Said for a long while, and later said, can be graphically edited. Enter the graphical edit command: Nm-connection-editor

I don't know what the author of this book is going to say. Did I meet the big hang God???!

Edit a network configuration file

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.