Linux Network configuration commands

Source: Internet
Author: User
Tags what interface

The most commonly used network configuration commands in Linux systems include Ifconfig, route, where ifconfig is used to view and configure network interfaces (usually NIC) information, including the IP address, mask, etc. of the network interface device, and the route is used to manage the routing tables in the Linux system kernel. Its biggest use is to set the static routing table entries, usually after the system with Ifconfig configuration network interface, use it to set the host or the IP address of a network segment should be sent through what interface and so on.

Ifconfig

The syntax for ifconfig is:

Ifconfig [-A] [-v] [-S] [[]

]


[[-]broadcast [

]]


[Netmask

]


[Up|down]

Where interface is the name of the network card, address for IP addresses, broadcast to set the broadcast address, followed by address is the IP of the broadcast addresses, netmask to set the subnet mask, after which address is the subnet mask IP, up and down settings The status of the current NIC, up means that the current network adapter is enabled, and down indicates that the current NIC is turned off.

The common parameters of Ifconfig are described below:

-A view all NIC status

-V View version information for the ifconfig command

-S View statistics

Example:

1) Set the IP address of the first NIC to 192.168.0.1:

Ifconfig eth0 192.168.0.1 (format: Ifconfig network device name IP address)

2) temporarily turn off or enable the network card:

Turn off the first Nic: Ifconfig eth0 down

Enable first NIC Ifconfig eth0 up

3) Set the subnet mask of the first NIC to 255.255.255.0:

Ifconfig eth0 netmask 255.255.255.0 (format: Ifconfig network device name netmask subnet mask)

We can also set the IP address and subnet mask at the same time:

Ifconfig eth0 192.168.0.1 netmask 255.255.255.0

4) View the status of the first NIC:

Ifconfig eth0

If you want to see all the network card status, use the Ifconfig command without parameters directly.

Ifconfig The status information of the output is very useful, let's briefly explain below:

There are several states that are more important:

Up/down: The network card is started, if it is down, it is certainly not available;

The number of errors packets in the RX packets is too large to indicate that the NIC is having problems receiving;

The number of errors packets in the TX packets is too large to indicate that there is a problem when sending the NIC;

Route

The syntax for the route command is:

Route [-cfvnee]

Route [-v] [-A family] add [-net|-host] target [netmask Nm] [GW GW] [metric N] [mod] [reinstate] [[Dev] If]

Route [-v] [-A family] del [-net|-host] target [GW GW] [netmask Nm] [METRICN] [[Dev] If]

Route [-v] [–version] [-h] [help]

The common parameters of the route are described below:

-V uses redundant output mode.

-A family specifies a specific address family (for example, "inet" "Inet6″).

-N Use a number to display the address such as 202.38.75.75 instead of explaining the domain name.

-e uses the same output format as netstat.

The-ee parameter produces very long outputs, including almost all the information for the kernel routing table.

The-net target is a network segment.

The-host target is a separate host.

-F shows that the kernel FIB routing table results may be changed by the-E and-ee parameters.

-C Displays the kernel-routed cache information.

Del Deletes a route table entry.

Add adds a route table entry.

Target network segment or host configured. Can be an IP, or a network or host name.

Netmask Nm The netmask used to indicate the route table entry to be added.

GW GW Any IP packet to the destination (target) is passed through this gateway.

Metric m sets the scale field (metric field) of the item in the routing table to M.

Example:

1) Add a route table entry, the network segment 192.168.0.x should go from the interface "Eth0″"

Route add-net 192.168.0.0 netmask 255.255.255.0 Dev eth0

2) Add a default route

Route add 0.0.0.0 GW gateway address

This routing rule is used if there are no other matching route entries.

3) Delete the default route

Route del 0.0.0.0 GW Gateway address

4) Sample output of the route command shows

The output format has the following columns:

Destination target network segment or host

Gateway address, if not set, then "*" means

Genmask Network Mask

Flags some of the possible tokens are as follows:

U (Route is active)
H (target is a host)
G (using Gateway)

R (table entries generated by reinstate route dynamic routing)

D (dynamically installed by daemon or redirect)

M (modified from routing daemon or redirect)

! (Reject route)

Metric route distance.

REF number of route entry references. (not used in Linux kernel)

Use to find the number of route entries.

Iface the output interface corresponding to the route table entry.


This article is from the "Carey" blog, make sure to keep this source http://careygg.blog.51cto.com/11084669/1733383

Linux Network configuration commands

Related Article

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.