Linux configuration NIC IP address command detailed introduction and some common network configuration commands 2010- A- - 0Comments Collection I want to contribute to the Linux command line under the configuration of the IP address is not as convenient as the graphical interface, completely need our manual configuration, the following will give you a few configuration methods: Immediate effect (restart after failure): Ifconfig eth0192.168.1.102Netmask255.255.255.0 //Add IP AddressRoute AdddefaultGw192.168.1.1 //add gateway to start effective: Vim/etc/sysconfig/network-scripts/ifcfg-eth0//(Some versions may not have vim in this editor such as CentOS, you may replace with VI) ipaddr=192.168.1.102//Add IP address netmask=255.255.255.0//Mask gateway=192.168.1.1//Add a gatewayThe final results are as follows: DEVICE=eth0 bootproto=StaticIpaddr=192.168.1.102netmask=255.255.255.0geteway=192.168.1.1Onboot=yes type=ethernet Note: Bootproto can modify DNS vim/etc/with the IP information set only in static moderesolv.conf changes can be effective immediately, start the same valid form to join NameServer= ***.***.***.***there can be up to three, as candidate modifications after the last failure host name immediately takes effect: hostname FC2 activation: VimThe/etc/sysconfig/network 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 the eth0 IP while activating the device: Ifconfig eth0192.168.4.1Netmask255.255.255.0Up Example 2: Configure eth0 alias device eth0:1IP, and add the route ifconfig eth0:1 192.168.4.2Route Add–host192.168.4.2Dev eth0:1Example 3: Activate (disable) device ifconfig eth0:1Up (Down) Example 4: View all (specified) network interface configuration ifconfig (eth0) —————————2. Use the route command to configure a route Example 1: Add to host routing route Add–host192.168.4.2Dev eth0:1Route Add–host192.168.4.1Gw192.168.4.250Example 2: Add a route to the network route add–net IP netmask mask eth0 route add–net IP netmask mask GW IP route add–net ip/ -eth1 Example 3: Add a default gateway route adddefaultGW IP Example 4: Remove routing route del–host192.168.4.1Dev eth0:1Example 5: View route information Route or Route-n (-n indicates that the name is not resolved and is listed faster than the route) —————————3. ARP Management Command Example 1: View ARP cache ARP Example 2: Add arp–s IP MAC Example 3: Remove Arp–d IP —————————4. IP is a powerful network configuration tool in the IPROUTE2 package that can replace some traditional network management tools. For example: ifconfig, route, etc., the above example can be fully implemented with the following IP command, and the IP command can achieve more functions. Here are some examples:4.0IP command Syntax IP [OPTIONS] OBJECT [command [ARGUMENTS]]4.1IP linkSet– Change the properties of the device. Abbreviation:Set, s example 1:up/down start/close the device. IP linkSetDev eth0 up this equals the traditional ifconfig eth0 up ifconfig eth0 down Example 2: Change the length of the device transmission queue. Parameters: Txqueuelen number or Txqlen number IP linkSetDev eth0 Txqueuelen -Example 3: Change the value of the network device MTU (maximum transmission unit). IP linkSetDev eth0 MTU theExample 4: Modify the MAC address of a network device. Parameters: Address lladdress IP linkSetDev eth0 Addressxx: on: 4f:xx: the: F14.2The IP link show– displays the device properties. Abbreviation: show, list, LST, sh, ls, l-s options occur 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.1IP address add– adds a new protocol address. Abbreviation: Add, a Example 1: Set a string for each address as the label. In order to and linux-2.0 The network alias is compatible, this string must start with the device name, followed by a colon, IP addr add local192.168.4.1/ -BRD + label Eth0:1The dev eth0 is equivalent to ifconfig eth0:5 192.168.4.1/ -IP addr Add Local192.168.4.1/ -Dev eth0 Example 2: Add an address 192 on the Ethernet interface eth0.168.20.0, the mask length is 24 bits (155.155.155.0), standard broadcast address, labeled ETH0:ALIAS:IP addr Add192.168.4.2/ -BRD + dev eth1 label eth1:1This command equals the traditional: ifconfig eth1:1 192.168.4.2/ -5.2IP Address delete– deletes a protocol address. Abbreviation: Delete, del, D IP addr del192.168.4.1/ -BRD +Dev eth0 label eth0:alias15.3IP Address show– displays the protocol address. Abbreviation: show, list, LST, sh, ls, l IP addr ls eth05.4. IP address flush– clears the protocol address. Abbreviation: Flush, f example 1: Delete belongs to private network 10.0.0.0/8 All addresses: Ip-s-S A f toTen/8Example 2: Canceling IP address IP for all Ethernet cards-4Addr Flush Label "Eth0″ —————————6. IP neighbour–neighbour/ARP Table management command abbreviation neighbour, neighbor, neigh, n command Add, change, replace, delete, Fulsh, show (or list)6.1IP neighbour add-Add a new adjacency entry IP neighbour change– Modify an existing entry IP neighbour replace– replace an entry abbreviation: Add, A;change, Chg;replace, re PL Example 1: On the device eth0, for address 10.0.0.3 Add a permanent ARP entry: IP neigh add10.0.0.3Lladdr0:0:0:0:0:1Dev eth0 nud Perm Example 2: Change status to reachable IP neigh chg10.0.0.3Dev eth0 nud reachable6.2. IP neighbour delete– Delete an adjacency entry Example 1: Remove an ARP entry on the device eth0 10.0.0.3IP neigh del10.0.0.3Dev eth06.3The. IP neighbour show– displays information about the Network Neighborhood. Abbreviation: show, list, sh, ls example 1:ip-s n ls193.233.7.254 193.233.7.254. Dev eth0 lladdrxx:xx: 0c: the: 3f: - ref 5Used A/ -/ -Nud reachable6.4The. IP neighbour flush– clears the adjacency entry. Abbreviation: Flush, f Example 1: (-S can show details) Ip-s-s n F193.233.7.254—————————7. Routing Table Management7.1. abbreviated route, RO, R7.5. routing table from linux-2.2 at the beginning, the kernel induces routes into many routing tables, which are numbered and numbered in the range 1 to 255. In addition, for convenience, you can also/etc/iproute2/Name the routing table in 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-Replace existing route abbreviation: Add, A;change, Chg;replace, repl Example 1: Set to Network 10.0.0/24 is routed through Gateway 193.233.7. $IP route add10.0.0/ -Via193.233.7.65Example 2: Modify to Network Ten.0.0/24 Direct route, so that it passes through the device dummy IP route Chg10.0.0/ -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 AdddefaultScopeGlobalNexthop Dev ppp0 nexthop Dev ppp1 ip route replacedefaultScopeGlobalNexthop Dev ppp0 nexthop Dev ppp1 Example 4: Set NAT route. In forwarding from 192.203.80Before the. 144 packet, the network address translation is performed before the address is converted to 193.233.7. theIP route add NAT192.203.80.142Via193.233.7.83Example 5: Implement packet-level load balancing, allowing packets to be emitted randomly from multiple routes. Weight can set weights. IP route ReplacedefaultEqualize Nexthop via211.139.218.145Dev eth0 Weight1Nexthop via211.139.218.145Dev eth1 Weight17.7. IP Route delete– Delete route abbreviation: Delete, Del, d Example 1: Remove the multipath route IP Route del that was added to the previous section commanddefaultScopeGlobalnexthop Dev ppp0 nexthop Dev ppp17.8. IP Route show-lists route abbreviations: show, list, sh, LS, l Example 1: Calculate using gated/BGP protocol number of routes IP route ls Proto GATED/BGP |WC1413 9891 79010Example 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-o option ip-o route ls cloned |WC159 2543 18707Example 3: List the routes inside the routing table TableID. The default setting is table Main. The TableID is either a true routing table ID or a string defined by the/etc/iproute2/rt_tables file, or a special value such as: all-lists the routes for all tables; cache-lists the contents of the route cache. IP ro ls193.233.7.82Tab Cache Example 4: List the contents of a routing table IP route LS Table fddi153 Example 5: List the contents of the default route table IP route ls This command equals traditional: route7.9. IP Route flush-Erase route Example 1: Delete routing table All Gateway routes in main (example: After the routing monitor hangs): IP-4RO Flush ScopeGlobalType Unicast Example 2: Clears all cloned IPv6 routes: IP-6-s-s RO Flush Cache Example 3: Clears all BGP routes after the gated program is hung: ip-s ro F Proto GATED/BGP example 4: Clear all IPv4 routes cache IP route Flush Cache * * * IPV4 Routing Cache isflushed.7.10IP routeGet-Get a single route. Abbreviation:Get
Linux configuration NIC IP address command detailed introduction and some common network configuration commands