Configure IP address under Linux

Source: Internet
Author: User

Transfer from http://www.cnblogs.com/lidp/archive/2009/12/02/1697480.html

Immediate effect:
Ifconfig eth0 192.168.1.102 netmask 255.255.255.0
Activation takes effect:
Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Join
ipaddr=192.168.1.102
netmask=255.255.255.0

Modify the default gateway
Immediate effect:
Route add default GW 192.168.1.1
Activation takes effect:
Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Join
gateway=192.168.1.1
The final results are 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 IP information that is set in static (static) mode
Modify DNS
Vim/etc/resolv.conf
Modified to take effect immediately, start the same effective

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

Modify Host Name
Immediate effect:
Hostname FC2
Activation takes effect:
Vim/etc/sysconfig/network
The form is as follows:
Networking=yes
hostname=rh-linux.fc.org
##########################################################
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 192.168.4.1 netmask 255.255.255.0 up
Example 2: Configure IP for eth0 alias device eth0:1 and add routes
Ifconfig eth0:1 192.168.4.2
Route add–host 192.168.4.2 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 192.168.4.2 Dev eth0:1
Route add–host 192.168.4.1 GW 192.168.4.250
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 192.168.4.1 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
Arp
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
IP [OPTIONS] OBJECT [COMMAND [ARGUMENTS]]

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.
Example:
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 192.168.4.1/28 BRD + label Eth0:1 Dev eth0
Equivalent to
Ifconfig Eth0:5 192.168.4.1/28
IP addr Add local 192.168.4.1/28 dev eth0
Example 2:
Add an address 192.168.20.0 on the Ethernet interface eth0 with a mask length of 24 bits (155.155.155.0), a standard broadcast address, and a label of Eth0:alias:
IP addr Add 192.168.4.2/24 brd + dev eth1 label eth1:1
This command equals the traditional:
Ifconfig eth1:1 192.168.4.2/24

5.2 IP Address delete– deletes 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– 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 10.0.0.0/8:
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 10.0.0.3:
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 neighbour delete– Delete an adjacency entry
Example 1: Remove an ARP entry on the device eth0 10.0.0.3
IP neigh del 10.0.0.3 dev eth0
6.3.ip Neighbour show– Displays information about the Network Neighborhood. Abbreviation: show, list, sh, 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 neighbour flush– clears the adjacency entry. Abbreviation: Flush, F
Example 1: (-S can show more information)
Ip-s-S N F 193.233.7.254
—————————
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 193.233.7.65
IP route add 10.0.0/24 via 193.233.7.65

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 192.203.80.144, network address translation is performed, and this address is converted to 193.233.7.83
IP route add Nat 192.203.80.142 via 193.233.7.83

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 211.139.218.145 Dev eth0
Weight 1 nexthop via 211.139.218.145 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 193.233.7.82 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 193.233.7.82
IP Route Get 193.233.7.82
193.233.7.82 Dev eth0 src 193.233.7.65 Realms inr.ac Cache MTU RTT
300
Example 2:
The search destination address is 193.233.7.82, from 193.233.7.82, the route that arrives from the eth0 device (this command produces a very interesting route, which is a loopback route to 193.233.7.82)
IP r G 193.233.7.82 from 193.233.7.82 iif eth0
193.233.7.82 from 193.233.7.82 dev eth0 src 193.233.7.65 Realms
Inr.ac/inr.ac
Cache

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 193.233.7.83 to 192.203.80.144 and route through table 1
IP ru add from 193.233.7.83 nat 192.203.80.144 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 192.168.4.89 Lookup fddi153
32764:from 192.168.4.88 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
2: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
(193.232.127.6, 224.0.1.39) Iif:unresolved
(193.232.244.34, 224.0.1.40) Iif:unresolved
(193.233.7.65, 224.66.66.66) Iif:eth0 Oifs:pimreg
Example 2: View ip-s Mr Ls 224.66/16
(193.233.7.65, 224.66.66.66) 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 192.31.7.104 local 192.203.80.1 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: 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.