Linux Static IP configuration

Source: Internet
Author: User

cat /etc/sysconfig/network-scripts/ifcfg-eth0device=Eth0bootproto=statichwaddr =xx: 0C:6 C: £ ºipaddr=192.168. 10.151 NETMASK=255.255. 255.0 GATEWAY=192.168. 10.254 onboot=yestype=ethernet

IP effective:
/sbin/ifdown eth0
/sbin/ifup eth0

Notification Gateway Update information:
/etc/init.d/network restart

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 means not resolving names, listing faster than 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
The use of the IP command is as follows:
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 equals the traditional # ifconfig eth0 up (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:

[Email protected] ~]# Ip-s-S linklseth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU theQdisc Pfifo_fast State up Qlen +Link/etherxx: 0c: in: 6c: -: toBRD FF:FF:FF:FF:FF:FF rx:bytes packets errors dropped overrun Mcast377968     4070     0       0       0       0RX Errors:length CRC frame FIFO missed0        0       0       0       0tx:bytes packets errors dropped carrier Collsns111952     663      0       0       0       0TX errors:aborted FIFO window heartbeat0        0       0       0[[Email protected]~]#

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
Example 2: Add an address 192.168.20.0 on the Ethernet interface eth0, 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
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-adds 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--Modify route
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 just tells the kernel,
This route is routed through a 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 a NAT route. 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 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 Wei Ght 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: Calculate 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--get 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. The IP route 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 300 RTT
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 MTU $ RTT iif eth0
8. IP route--routing policy Database management commands
Command Add, delete, show (or list)
Note: Policy routing is not equal to the routing policy (rouing).
In some cases, we don't just need to determine the route through the destination address of the packet, but there may also be other domains: The source address, the IP protocol, the Transport layer port, or even the payload of the packet.
This is called: Policy Routing.
8.5. IP rule Add-Inserts a new rule
IP Rule Delete--delete rule
Abbreviations: Add, A;delete, Del, D
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--Remove 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: Remove # ip maddr del 33:33:00:00:00:01 dev Dummy
10.ip Mroute--Multicast routing cache management
10.4. IP mroute Show--list 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
IP tunnel--channel configuration
Abbreviation Tunnel, TUNL
11.4.ip Tunnel Add-adds a new channel
IP Tunnel Change-modifies an existing channel
IP Tunnel Delete--Deletes 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

Linux static IP configuration

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.