Linux Network configuration commands

Source: Internet
Author: User
Tags aliases nameserver

Network Address classification:
Host bit all 0: network address
Host bit full 1: Broadcast address
Class A: Starting with 0, 8-bit network bit
0.0.0.0~127.255.255.255
127 for loopback addresses
How many hosts are accommodated: 2^24-2
Class B: Starting with 10, 16 bit network bit,
128.0.0.0~191.255.255.255
How many hosts are accommodated: 2^16-2
Class C: Starting with 110, 24-bit network bit
192.0.0.0~223.255.255.255
Accommodates multiple fewer hosts: 2^8-2
Class D: Starting with 1110 to make a multicast address
224.0.0.0~239.255.255.255
Class E: Starting with 1111, preserving the address
240.0.0.0~255.255.255.255

Private Address:
Class A: 10.0.0.0/8
Class B: 172.16.0.0/16-172.31.0.0/16
Class C: 192.168.0.0/24-192.168.255.0/24

In addition, there are some special-purpose addresses in IPV4:
0.0.0.0/8: A host in the local network, only used as the source IP address
127.0.0.0/8: loopback address, usually only with 127.0.0.1
169.254.0.0/16: "Link-local" address, used only for one link, usually automatically assigned
192.0.0.0/24:IETF Agreement Assignment (IANA reserved)
192.0.2.0/24: Approved for TEST-NET-1 addresses in the document and does not appear on the public internet
192.88.99.0/24: For 6to4 relay (anycast address)
198.18.0.0/15: For benchmarking and performance testing
198.51.100.0/24:tese-net-2 address, for use in documents
203.0.113.0/24:tese-net-3 address, for documentation
255.255.255.255/32: Local network (limited) broadcast address

If you want to connect a host to the network, you need to configure the information:
IP address, subnet mask, gateway, hostname, DNS server address (General configuration 2, Standby)

In Linux, the network is the function of the kernel, if there are more than one network card, regardless of which card entered, as long as a few network cards have this address, you can receive.

Identification of network interfaces in Linux:
Lo: Local loopback interface
eth#: #表示数字, Ethernet NIC Interface
ppp#: Point-to-point connection

Ifconfig and IP commands
Ifconfig usage:
Ifconfig [eth#]: Display configuration information for the interface
Ifconfig eth#:xxxx ip/netmask: Setting aliases for network card devices
Ifconfig eth# "IP (IP address)/mask (subnet mask)" "Up|down": Turn network interface on or off
The configured address, which takes effect immediately, but restarts the network service or host, will fail

Network Service files: can be manipulated with the following parameters
rhel5:/etc/init.d/network {Start|stop|restart|status}
RHEL6:/etc/init.d/networkmanager {start|stop|restart|status}


To configure the gateway:
Route command: Common options Add,del
Add: Adding
-host: Host Routing
-net: Network Routing
Route add-net or-host DEST GW (keyword) nexthop (Next hop address)
Route add default GW (keyword) nexthop (Next hop address)
Del: Delete
-host
-net
Route del Default (0.0.0.0)
View:
Route-n: Digitally display information about each host or port

Does not write in the configuration file, the changes made after restarting the network service or the host fails, so it can be used by the following configuration file for permanent, but they do not take effect immediately, need to restart the network service or host will take effect, because the configuration file will only be read at the moment the host is opened

Network configuration file:
/etc/sysconfig/network

Network Interface configuration file:
/etc/sysconfig/network-scripts/ifcfg-interface_name
Device=: The associated device name, to be consistent with the second half of the file name "Interface_name";
BOOTPROTO={STATIC|NONE|DHCP|BOOTP}: Boot protocol; To use static addresses, use either statics or NONE;DHCP to obtain an address using a DHCP server;
Ipaddr=: IP Address
netmask=: Subnet Mask
Gateway=: Set default gateway;
Onboot=: Whether the network interface is activated automatically when booting;
Hwaddr=: Hardware address, to be consistent with the address in the hardware;
Userctl={yes|no}: Whether to allow ordinary users to control this interface;
Peerdns={yes|no}: Whether the DNS address specified by the DHCP server is accepted when Bootproto is DHCP;


Routed configuration file:
/ETC/SYSCONFIG/NETWORK-SCRIPTS/ROUTE-ETHX, no words can create a, ethX to be the same as the name of the network card
Add format one:
DEST (host or network (with mask) via (keyword) nexthop (next hop)

Add format two: #代表组号, ....
address# (destination address) =
netmask# (subnet mask) =
gateway# (Next hop) =


Configure host Name:
hostname hostname
Effective immediately, but not permanently;
Configuration Profile/etc/sysconfig/network
Format:
Hostname=


The DNS server specifies only one method: through the configuration file/etc/resolv.conf
Format: General configuration of more than two
NameServer dns_ip_1
NameServer dns_ip_2


When there is no DNS server and requires host name access, you can specify the local resolution:
Configuration file/etc/hosts:
Format:
Host IP host name host Alias

When a host name is entered, it is looked up under/etc/hosts, and if it is not found, it will go to the DNS server to find


IP commands in the IPROUTE2 package: IP address, routing, routing management, Policy routing, etc. can be configured
Format:
Ip:
Link: Configure network interface properties
Show: View the address of the network interface
-S: Display statistics
Ip-s Link Show
Set: Sets the Address property of the network interface
IP link Set DEV (NIC) {Up|down}

Addr: Configure protocol Address
Add: Adding
IP addr add address dev dev (device)
If you already have an IP address in dev, the configured address becomes a non-primary address, and you can ping the
You can use the label option to work with aliases:
IP addr Add ip/netmask dev (keyword) eth1 label (keyword) eth#:xxx
You can also create aliases with Ifconfig:
Ifconfig eth#:xxxx Ip/netmask
Configuration file:/etc/sysconfig/network-scripts/ifcfg-eth#:xxxx
DEVICE=ETH#:XXXX, the associated device name, to be consistent with the second half of the file name "Interface_name";
Del: Delete
IP addr del ADDRESS dev (key) dev (device)
Show: View
Can be used to display eligible
IP addr Show dev (keywords) dev (device) to PREFIX (match character)
Flush: Clear
Can be used to clear the eligible
IP addr Flush dev (keyword) dev (device) to PREFIX (match character)
Route: Configure Routing
Route add-net ip/netmask GW IP
IP route add to Ip/netmask Dev (device) device name via (Next hop) IP address

Linux Network configuration commands

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.