Linux nic ip address configuration commands and some common network configuration commands

Source: Internet
Author: User
The IP address configuration in the Linux command line is not as convenient as in the graphic interface. we need to manually configure the IP address. The following describes several configuration methods: & nbsp; takes effect immediately (expired after restart ): ifconfigeth0192.168.1.102netmask00000000255.0 & nbsp; // add the IP address routeadddefau

The IP address configuration in the Linux command line is not as simple as that in the graphic interface. you need to manually configure the IP address. The following describes several configuration methods:

 

Effective immediately (expired after restart ):
Ifconfig eth0 192.168.1.102 netmask 255.255.255.0 // add an IP address

Route add default gw 192.168.1.1 // add a Gateway
Start effective:
Vim/etc/sysconfig/network-scripts/ifcfg-eth0 // (in some versions, the vim editor such as centos may not be available, and you may replace it with vi)
IPADDR = 192.168.1.102 // add an IP address
NETMASK = 255.255.255.0 // mask
GATEWAY = 192.168.1.1 // add a GATEWAY

The final result is as follows:
DEVICE = eth0
BOOTPROTO = static
IPADDR = 192.168.1.102
NETMASK = 255.255.255.0
GETEWAY = 192.168.1.1
ONBOOT = yes
TYPE = Ethernet
Note: BOOTPROTO can only use the configured IP address in static mode.
Modify dns
Vim/etc/resolv. conf
The modification takes effect immediately and starts as well.

Form
Add nameserver = ***.***.***.***
Up to three candidates can be selected as candidates after the previous failure.

Modify host name
Effective immediately:
Hostname fc2
Start effective:
Vim/etc/sysconfig/network
The format is as follows:
NETWORKING = yes
HOSTNAME = rh-linux.fc.org
######################################## ##################
First, understand the traditional network configuration commands:
1. use the ifconfig command to configure and view network interfaces
Example 1: configure the IP address of eth0 and activate the device at the same time:
Ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up
Example 2: configure the IP address of the eth0 alias device eth0: 1 and add a route
Ifconfig eth0: 1 192.168.4.2
Route add? Host 192.168.4.2 dev eth0: 1
Example 3: Activate (disable) a device
Ifconfig eth0: 1 up (down)
Example 4: View All (specified) network interface configurations
Ifconfig (eth0)
---------
2. use the route command to configure the route table
Example 1: Add to host route
Route add? Host 192.168.4.2 dev eth0: 1
Route add? Host 192.168.4.1 gw 192.168.4.250
Example 2: Route added to the network
Route add? Net IP netmask MASK eth0
Route add? Net IP netmask MASK gw IP
Route add? Net IP/24 eth1
Example 3: Add a default gateway
Route add default gw IP
Example 4: Delete a route
Route del? Host 192.168.4.1 dev eth0: 1
Example 5: View route information
Route or route-n (-n indicates that the name is not parsed, and the list speed is faster than route)
---------
3. ARP management commands
Example 1: View ARP cache
Arp
Example 2: Add
Arp? S IP MAC
Example 3: delete
Arp? D IP
---------
4. ip is a powerful network configuration tool in iproute2, which can replace some traditional network management tools.

For example, ifconfig and route,
The preceding example can be fully implemented using the following ip command, and the ip command can implement more functions. The following describes some examples:

4.0 ip command syntax
Ip [OPTIONS] OBJECT [COMMAND [ARGUMENTS]

4.1 ip link set? Change the properties of a device. abbreviation: set, s

Example 1: up/down start/close the device.
Ip link set dev eth0 up
This is equal to the traditional
Ifconfig eth0 up
Ifconfig eth0 down
Example 2: change the length of the device transmission queue.
Parameter: txqueuelen NUMBER or txqlen NUMBER
Ip link set dev eth0 txqueuelen 100
Example 3: Change the MTU value of the network device.
Ip link set dev eth0 mtu 1500
Example 4: modify the MAC address of a network device.
Parameter: address LLADDRESS
Ip link set dev eth0 address 00: 01: 4f: 00: 15: f1

4.2 ip link show? Display Device Properties. abbreviations: show, list, lst, sh, ls, l
If the-s option appears twice or more times, the ip will output more detailed error information statistics.
Example:
Ip-s link ls eth0
This command is equivalent to the traditional
Ifconfig eth0
---------
5.1 ip address add? Add a new protocol address. abbreviation: add,
Example 1: set a string for each address as a tag. To be compatible with the Linux-2.0's network alias, this string must start with the device name, followed by a colon,
Ip addr add local 192.168.4.1/28 brd + label eth0: 1 dev eth0
Equivalent
Ifconfig eth0: 5 192.168.4.1/28
Ip addr add local 192.168.4.1/28 dev eth0
Example 2: Add an IP address 192.168.20.0 to the Ethernet interface eth0. the mask length is 24 bits (155.155.155.0), the standard broadcast address, and the label is eth0: Alias:
Ip addr add 192.168.4.2/24 brd + dev eth1 label eth1: 1
This command is equivalent to the traditional one:
Ifconfig eth1: 1 192.168.4.2/24

5.2 ip address delete? Delete a protocol address. abbreviation: delete, del, d
Ip addr del 192.168.4.1/24 brd + dev eth0 label eth0: Alias1

5.3 ip address show? Display protocol address. abbreviations: show, list, lst, sh, ls, l
Ip addr ls eth0

5.4.ip address flush? Purge protocol address. abbreviation: flush, f
Example 1: delete all addresses in the private network 10.0.0.0/8:
Ip-s a f to 10/8
Example 2: cancel the IP addresses of all Ethernet cards
Ip-4 addr flush label "eth0 ″
---------
6. ip neighbor? Neighbor/arp table management command
Abbreviations: neighbor, neighbor, neigh, n
Command add, change, replace, delete, fulsh, show (or list)

6.1 ip neighbor add-add a new adjacent entry
Ip neighbor change? Modify an existing entry
Ip neighbor replace? Replace an existing entry
Abbreviation: add, a; change, chg; replace, repl
Example 1: add a permanent ARP entry for address 10.0.0.3 on the eth0:
Ip neigh add 10.0.0.3 lladdr 0: 0: 0: 0: 0: 1 dev eth0 nud perm
Example 2: change the status to reachable.
Ip neigh chg 10.0.0.3 dev eth0 nud reachable

6.2.ip neighbor delete? Delete an adjacent entry
Example 1: delete an ARP entry 10.0.0.3 on the eth0 device.
Ip neigh del 10.0.0.3 dev eth0
6.3.ip neighbor show? Displays information about network neighbors. abbreviations: show, list, sh, and ls.
Example 1: ip-s n ls 193.233.7.254
193.233.7.254. dev eth0 lladdr 00: 00: 0c: 76: 3f: 85 ref 5 used 12/13/20 nud reachable
6.4.ip neighbor flush? Clear the adjacent entries. abbreviation: flush, f
Example 1: (-s can display details)
Ip-s n f 193.233.7.254
---------
7. route table management
. Abbreviated route, ro, r
7. 5. route table
Starting from the Linux-2.2, the kernel has summarized the route into many routing tables that are numbered in the range of numbers 1 to 255. In addition,
For convenience, you can also name the route table in/etc/iproute2/rt_tables.
By default, all routes are inserted into the main table (No. 254. During route query, the kernel only uses the route table main.

7.6.ip route add-add new route entry
Ip route change-modify a route
Ip route replace-replace existing routes
Abbreviation: add, a; change, chg; replace, repl
Example 1: The route destined for 10.0.0/24 goes through the Gateway 193.233.7.65
Ip route add 10.0.0/24 via 193.233.7.65

Example 2: modify the direct route to 10.0.0/24 so that it passes through the device dummy
Ip route chg 10.0.0/24 dev dummy

Example 3: achieve link load balancing. add the default multi-path route so that ppp0 and ppp1 can share the load (note: The scope value is not required, but it only tells the kernel that the route must go through the gateway instead of directly connected. In fact, if you know the address of the remote endpoint, it is better to use the via parameter ).
Ip route add default scope global nexthop dev ppp0 nexthop dev ppp1
Ip route replace default scope global nexthop dev ppp0 nexthop dev ppp1
Example 4: configure a NAT route. Before forwarding a packet from 192.203.80.144, convert the network address to 193.233.7.83.
Ip route add nat 192.203.80.142 via 193.233.7.83

Example 5: achieve packet-level load balancing and allow random packet sending from multiple routes. You can set the weight for weight.
Ip route replace default equalize nexthop via 211.139.218.145 dev eth0 weight 1 nexthop via 211.139.218.145 dev eth1 weight 1

7.7.ip route delete? Delete a route
Abbreviation: delete, del, d
Example 1: delete the multi-path route added to the previous command
Ip route del default scope global nexthop dev ppp0 nexthop dev ppp1

7.8.ip route show-list routes
Abbreviations: show, list, sh, ls, l

Example 1: calculate the number of routes using the gated/bgp protocol
Ip route ls proto gated/bgp | wc
1413 9891 79010

Example 2: calculate the number of cached routes. the-o option is required because the cached route attributes may be greater than one row.
Ip-o route ls cloned | wc
159 2543 18707
Example 3: list the routes in the TABLEID of the route table. The default setting is table main. TABLEID is either a real route table ID or a string defined in the/etc/iproute2/rt_tables file,
Or the following special values:
All-lists the routes of all tables;
Cache-list the content of the route cache.
Ip ro ls 193.233.7.82 tab cache
Example 4: list the contents of a route table
Ip route ls table fddi153

Example 5: list the content of the default route table
Ip route ls
This command is equivalent to the traditional: route

7.9.ip route flush-erased route table
Example 1: delete all Gateway routes in the main route table (example: after the route monitoring program fails ):
Ip-4 ro flush scope global type unicast
Example 2: clear all cloned IPv6 routes:
Ip-6-s ro flush cache
Example 3: clear all BGP routes after the gated program fails:
Ip-s ro f proto gated/bgp
Example 4: clear all ipv4 route caches
Ip route flush cache
* ** IPv4 routing cache is flushed.

7.10 ip route get-get a single route. abbreviation: get

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.