Configure IP address under Linux

Source: Internet
Author: User

Transfer from

Immediate effect:
Ifconfig eth0 netmask
Activation takes effect:

Modify the default gateway
Immediate effect:
Route add default GW
Activation takes effect:
The final results are as follows:
Note: Bootproto can only use IP information that is set in static (static) mode
Modify DNS
Modified to take effect immediately, start the same effective

Join Nameserver= ***.***.***.***
Can have up to three, as a candidate after the last failure

Modify Host Name
Immediate effect:
Hostname FC2
Activation takes effect:
The form is as follows:
First, learn about the traditional network configuration commands:
1. Configure and view network interface conditions using the Ifconfig command
Example 1: Configure eth0 IP to activate the device at the same time:
Ifconfig eth0 netmask up
Example 2: Configure IP for eth0 alias device eth0:1 and add routes
Ifconfig eth0:1
Route add–host Dev eth0:1
Example 3: Activating (disabling) a device
Ifconfig eth0:1 up (down)
Example 4: View all (specified) network interface configuration
Ifconfig (eth0)
2. Configure the routing table with the route command
Example 1: Add to host route
Route add–host Dev eth0:1
Route add–host GW
Example 2: Add a route to a 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: Remove a route
Route del–host Dev eth0:1
Example 5: Viewing routing information
Route or Route-n (-n indicates that the name is not resolved and is listed faster than the route)
3.ARP Management Commands
Example 1: Viewing the ARP cache
Example 2: Adding
Arp–s IP MAC
Example 3: Deleting
Arp–d IP
4. IP is a powerful network configuration tool in the Iproute2 package, which can replace some traditional network management tools. For example: ifconfig, route, etc.,
The above example can be fully implemented with the following IP commands, and the IP command can achieve more functionality. Here are some examples:

4.0 syntax for IP commands

4.1 IP link set– changes the properties of the device. Abbreviation: Set, S

Example 1:up/down starting/shutting down 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 value of the network device MTU (maximum transmission unit).
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– Displays the device properties. Abbreviation: show, list, LST, sh, LS, l
The-s option occurs two or more times, and IP outputs more detailed error information statistics.
Ip-s-S link ls eth0
This command equals the traditional
Ifconfig eth0
5.1 IP Address add– Add a new protocol address. Abbreviation: Add, a
Example 1: Set a string for each address as a label. To be compatible with Linux-2.0 's network aliases, this string must start with the device name, followed by a colon,
IP addr Add local BRD + label Eth0:1 Dev eth0
Equivalent to
Ifconfig Eth0:5
IP addr Add local dev eth0
Example 2:
Add an address on the Ethernet interface eth0 with a mask length of 24 bits (, a standard broadcast address, and a label of Eth0:alias:
IP addr Add brd + dev eth1 label eth1:1
This command equals the traditional:
Ifconfig eth1:1

5.2 IP Address delete– deletes a protocol address. Abbreviation: Delete, Del, D
IP Addr del BRD + dev eth0 label eth0:alias1

5.3 IP Address show– displays protocol addresses. Abbreviation: show, list, LST, sh, LS, l
IP addr ls eth0

5.4.IP address flush– clears protocol addresses. Abbreviation: Flush, F
Example 1: Delete all addresses that belong to the private network
Ip-s-S A f to 10/8
Example 2: Canceling the IP address of all Ethernet cards
Ip-4 Addr Flush Label "Eth0″
6. IP neighbour–neighbour/arp Table Management commands
Abbreviations neighbour, neighbor, Neigh, n
command Add, change, replace, delete, Fulsh, show (or list)

6.1 IP Neighbour add-Add a new adjacency entry
IP neighbour change– Modifying an existing entry
IP neighbour replace– Replace an existing entry
Abbreviations: Add, A;change, Chg;replace, REPL
Example 1: On the device eth0, add a permanent ARP entry for address
IP neigh add lladdr 0:0:0:0:0:1 dev eth0 nud Perm
Example 2: Change the status to reachable
IP neigh chg dev eth0 nud reachable

6.2.ip neighbour delete– Delete an adjacency entry
Example 1: Remove an ARP entry on the device eth0
IP neigh del dev eth0
6.3.ip Neighbour show– Displays information about the Network Neighborhood. Abbreviation: show, list, sh, ls
Example 1:ip-s n ls Dev eth0 lladdr 00:00:0c:76:3f:85 ref 5 used 12/13/20 Nud
6.4.ip neighbour flush– clears the adjacency entry. Abbreviation: Flush, F
Example 1: (-S can show more information)
Ip-s-S N F
7. Routing Table Management
7.1. Abbreviated route, RO, R
7.5. Routing table
Starting with Linux-2.2, the kernel induces routes into many routing tables, which are numbered and numbered in the range 1 to 255. Other than that
For convenience, you can also name the routing table in/etc/iproute2/rt_tables.
By default, all routes will be inserted into the table main (number 254). In a routing query, the kernel uses only the routing table main.

7.6.ip Route add-Add new route
IP route change-modifying routes
IP route replace-replaces existing routes
Abbreviations: Add, A;change, Chg;replace, REPL
Example 1: Set the route to the network 10.0.0/24 through the gateway
IP route add 10.0.0/24 via

Example 2: Modify the direct route to the network 10.0.0/24 so that it passes through the device dummy
IP route chg 10.0.0/24 Dev Dummy

Example 3:
Implement link load balancing. Join the default multipath route and let Ppp0 and Ppp1 share the load (note: The scope value is not required, it simply tells the kernel that the route is routed through the gateway rather than directly connected.) In fact, if you know the address of the remote endpoint, it's better to use the Via parameter to set it up.
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:
Set up NAT routes. Before forwarding packets from, network address translation is performed, and this address is converted to
IP route add Nat via

Example 5: Implement packet-level load balancing, allowing packets to be emitted randomly from multiple routes. Weight
You can set weights.
IP route replace default equalize nexthop via Dev eth0
Weight 1 nexthop via dev eth1 weight 1

7.7.ip Route delete– Delete route
Abbreviation: Delete, Del, D
Example 1: Remove a multipath route joined by the previous section command
IP route del default scope global nexthop dev ppp0 nexthop Dev ppp1

7.8.ip Route show-List routes
Abbreviation: 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:
Calculates the number of bars in the route cache, because the properties of the cached route may be greater than one row, so you need to use the-o option
Ip-o Route LS cloned |WC
159 2543 18707
Example 3: List the routes inside the routing table TableID. The default setting is table
Main TableID is either a real routing table ID or a string defined by the/etc/iproute2/rt_tables file,
or the following special values:
all-lists the routes for all tables;
cache-lists the contents of the route cache.
IP RO ls tab cache
Example 4: Listing the contents of a routing table
IP route ls Table fddi153

Example 5: List the contents of the default routing table
IP Route ls
This command equals the traditional: route

7.9.ip Route flush-Erase route table
Example 1: Remove all gateway routes in the routing table main (example: After the routing monitor hangs):
ip-4 RO Flush Scope Global type unicast
Example 2: Clear all IPv6 routes that are cloned:
Ip-6-s-s RO Flush Cache
Example 3: Clear all BGP routes after the gated program has been hung out:
Ip-s ro F Proto GATED/BGP
Example 4: Clear all IPv4 route cache
IP route Flush Cache
IPV4 routing cache is flushed.

7.10 IP Route get-obtains a single route. Abbreviation: GET, G
Use this command to obtain a route to the destination address and its exact contents.
The IP route get command and the IP Route show command perform different actions. IP route
The show command simply shows the existing route, and the IP route get command will derive a new route if necessary.
Example 1: Searching for routes to
IP Route Get Dev eth0 src Realms Cache MTU RTT
Example 2:
The search destination address is, from, the route that arrives from the eth0 device (this command produces a very interesting route, which is a loopback route to
IP r G from iif eth0 from dev eth0 src Realms

Example 1: Route a packet from the source address 192.203.80/24 by routing table Inr.ruhep
IP ru add from 192.203.80/24 table Inr.ruhep Prio 220

Example 2: Convert the source address of a datagram with a source address of to and route through table 1
IP ru add from nat table 1 Prio 320

Example 3: Delete a useless default rule
IP ru del prio 32767

8.7. IP rule show-List routing rules
Abbreviation: show, list, sh, LS, l
Example 1:
IP ru ls
0:from All lookup Local
32762:from Lookup fddi153
32764:from Lookup fddi153
32766:from All lookup Main
32767:from All Lookup 253
9. IP maddress-Multicast address management
Abbreviation: show, list, sh, LS, l
9.3.ip maddress show-List multicast addresses
Example 1:
IP maddr ls Dummy

9.4. IP maddress add-join a multicast address
IP maddress delete-Delete multicast address
Abbreviations: Add, A;delete, Del, D
With these two commands, we can add/remove the link-layer multicast address that is listening on the network interface. This command only manages link-layer addresses.

Example 1: Add IP maddr add 33:33:00:00:00:01 dev Dummy
Example 2: View
Ip-o maddr ls Dummy
Link 33:33:00:00:00:01 users 2 static
Link 01:00:5e:00:00:01
Example 3: Deleting
IP maddr del 33:33:00:00:00:01 dev Dummy
10.IP mroute-Multicast Routing cache management

10.4. IP mroute show-listing multicast route cache entries
Abbreviation: show, list, sh, LS, l

Example 1: View IP mroute ls
(, Iif:unresolved
(, Iif:unresolved
(, Iif:eth0 Oifs:pimreg
Example 2: View ip-s Mr Ls 224.66/16
(, Iif:eth0 Oifs:pimreg
9383 packets, 300256 bytes
One. IP tunnel-Channel Configuration
Abbreviation Tunnel, TUNL

11.4.ip Tunnel add-Add a new channel
IP tunnel change-Modifying an existing channel
IP tunnel delete-Delete a channel
Abbreviations: Add, A;change, Chg;delete, Del, D
Example 1: Establish a point-to-point channel with a maximum TTL of 32
IP tunnel Add Cisco mode sit remote local TTL 32

11.4.ip tunnel show-List existing channels
Abbreviation: show, list, sh, LS, l
Example 1:ip-s TUNL ls Cisco
IP monitor and rtmon-status monitoring
IP commands can be used to continuously monitor the status of devices, addresses, and routes. The format of this command option is a bit different, the command option is named Monitor, followed by the operand:
IP monitor [file file] [all | Object-list]
Example 1:
Rtmon File/var/log/rtmon.log
Example 2:
IP Monitor File/var/log/rtmon.log r

Configure IP address under Linux

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: 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.