Linux Learning notes--Network attribute management

Source: Internet
Author: User
Tags new set nameserver

Linux Network attribute configuration is divided into two types

Statically specified

by command: Ifcfg:ifconfig,route,netstat

Ip:object {link, addr, route}, SS, TC

You can also specify through a configuration file: System-config-network-tui

In addition, a new set of commands was added to CentOS 7: nmcli, Nmtui

Dynamic allocation

Dhcp

Here's how to use each command

Ifcfg

Ifconfig command
Ifconfig [Interface]
# Ifconfig–a View All interface status

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m01/73/da/wkiol1yi39vrqmo7aabhuk4kyyu172.jpg "height="/>
# ifconfig IFACE [Up|down] Open/close specified port
Ifconfig interface [Aftype] options | Address ...
# ifconfig IFACE Ip/mask [up]
# ifconfig IFACE IP netmask MASK

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/73/dd/wkiom1yi39oy8qxnaaa2comc8ae466.jpg "height="/>

Route command
Routing Management Commands
View: Route-n
Add: Route add
Route add [-net|-host] target [netmask Nm] [GW GW] [[Dev] If]

Target: 192.168.1.3 Gateway: 192.168.31.1

~]# Route add-host 192.168.1.3 GW 192.168.31.1 Dev eth0

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/73/dd/wkiom1yi39pgeusjaaampkeb2fa003.jpg "height="/>

Target: 192.168.0.0 Gateway: 192.168.31.1
~]# Route add-net 192.168.0.0 netmask 255.255.255.0 gw 192.168.31.1 Dev eth0
~]# Route add-net 192.168.0.0/24 GW 192.168.31.1 Dev eth0

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m01/73/dd/wkiom1yi39sqz2rwaaal1bwpsto131.jpg "height="/>

Default route, Gateway: 172.16.0.1
~]# Route add-net 0.0.0.0 netmask 0.0.0.0 GW 192.168.31.1
~]# route add default GW 192.168.31.1

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/73/dd/wkiom1yi39szwkuuaabddiv96ug916.jpg "height="/>

Delete: Route del
Route del [-net|-host] target [GW GW] [netmask Nm] [[Dev] If]

Target: 192.168.1.3 Gateway: 192.168.31.1

~]# Route Del-host 192.168.1.3

Target: 192.168.0.0 Gateway: 192.168.31.1
~]# Route del-net 192.168.0.0 netmask 255.255.255.0

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/73/dd/wkiom1yi39tx10whaaba3qdkhno918.jpg "height="/>

Netstat command:

Show Network Connections:
netstat [--tcp|-t] [--udp|-u] [--raw|-w] [--listening|-l] [--all|-a] [--numeric|-n] [--EXTEND|-E[--EXTEND|-E]] [-- PROGRAM|-P]
-T:TCP protocol Related
-U:UDP protocol Related
-w:raw Socket Related
-L: In listening state
-A: all States
-N: Displays the IP and port numerically;
-E: Extended format
-P: Show related processes and PID

Common combinations:
-tan,-uan,-TNL,–UNL

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/73/da/wkiol1yi392q1avfaadfnxfdccs714.jpg "height=" 186 "/>

Show route table:
netstat {--route|-r} [--numeric|-n]
-R: Show kernel routing table
-N: Number format

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/73/da/wkiol1yi392cnddcaabdptdaocc852.jpg "height="/>

Display Interface Statistics:
netstat {--interfaces|-i|-i} [iface] [--all|-a] [--EXTEND|-E] [--program|-p] [--numeric|-n]

# netstat-i
# netstat-i IFACE

Ip

IP command:
IP [OPTIONS] OBJECT {COMMAND | help}

OBJECT: = {link | addr | route}

Link OBJECT:
IP link

Set
Dev IFACE
You can set properties:
Up and down: Activates or disables the specified interface;

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m01/73/dd/wkiom1yi39wdbskoaaa-etsxdfc415.jpg "height="/>

Show
[Dev IFACE]: Specify interface
[Up]: Show only interfaces that are in the active state

IP Address

IP Addr {add | del} ifaddr dev STRING
[Label label]: Indicates the NIC alias when adding an address
[Scope {Global|link|host}]: Indicates scope
Global: Globally available;
Link: only links are available;
Host: the machine is available;

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/73/dd/wkiom1yi39xdxig4aab5kb_cbyq702.jpg "height="/>

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/73/dd/wkiom1yi39ahkrr9aab3jd3p3xu886.jpg "height="/>
[Broadcast address]: Specify broadcast addresses

IP address show-look at protocol addresses
[Dev DEVICE]
[Label PATTERN]
[Primary and secondary]

IP Address Flush-flush protocol addresses
Use format with show

IP route

IP route add
Add route: IP route add TARGET via GW dev IFACE src source_ip
TARGET:
Host Routing: IP
Network routing: Network/mask

Add Gateway: IP route add defalt via GW Dev IFACE

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/73/dd/wkiom1yi39bqkfpiaab-clit3ly642.jpg "height="/>

IP route Delete
Delete route: IP route del TARGET

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m01/73/dd/wkiom1yi39asmyxsaacggli20gu752.jpg "height="/>

IP Route Show

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m02/73/dd/wkiom1yi39ewjskpaaan0ezhwls373.jpg "height="/>
IP Route Flush
[Dev IFACE]
[Via PREFIX]

SS Command:
Format: ss [OPTION] ... [FILTER]
Options:
-T:TCP protocol Related
-U:UDP protocol Related
-W: Bare Socket related
-x:unix Sock Related
-l:listen State of connection
-A: All
-N: Number format
-P: Related programs and PID
-E: Extended information
-M: Memory usage
-O: Timer letter

Common combinations:
-tan,-TANL,-tanlp,–uan

650) this.width=650; "title=" image "style=" border-top:0px;border-right:0px;background-image:none;border-bottom:0 px;padding-top:0px;padding-left:0px;border-left:0px;padding-right:0px; "border=" 0 "alt=" image "src=" http:// S3.51cto.com/wyfs02/m00/73/dd/wkiom1yi39ejqscjaacgfixwnhk903.jpg "height=" 151 "/>

Modifying a configuration file can also be set for network properties

DNS server Specifies
/etc/resolv.conf
NameServer DNS_SERVER_IP1
NameServer DNS_SERVER_IP2
NameServer DNS_SERVER_IP3

IP, MASK, GW, DNS-related configuration files:/etc/sysconfig/network-scripts/ifcfg-iface

Routing-related configuration files:/etc/sysconfig/network-scripts/route-iface

/etc/sysconfig/network-scripts/ifcfg-iface:
Device: Devices to which this profile applies;
HWADDR: The MAC address of the corresponding device;
Bootproto: The address configuration protocol used when activating this device, commonly used DHCP, static, none, BOOTP;
NM_CONTROLLED:NM is the abbreviation of NetworkManager, whether the NIC accepts NM control, CentOS6 is recommended as "no";
Onboot: Whether this device is activated at system boot time;
Type: interface types; common Ethernet, Bridge;
UUID: The unique identification of the device;

IPADDR: Specify the IP address;
NETMASK: Subnet mask;
Gateway: Default gateways;
DNS1: The first DNS server points to;
DNS2: The second DNS server points to;

Userctl: Whether the ordinary user can control the device;
Peerdns: If the value of Bootproto is "DHCP", whether the DNS server assigned by DHCP server is allowed to point to information directly to the/etc/resolv.conf file;

/etc/sysconfig/network-scripts/route-iface
Two different styles:
(1) TARGET via GW

(2) Define one route per three lines
Address#=target
Netmask#=mask
Gateway#=gw

In addition, the CentOS 7 network configuration adds a new set of commands

Address Configuration Tool: Nmcli
NMCLI [OPTIONS] OBJECT {COMMAND | help}

Device-show and manage network interfaces

Connection-start, stop, and manage network connections

How to modify properties such as IP address:
#nmcli connection Modify IFACE [+|-]setting.property value
Setting.property:
Ipv4.addresses
Ipv4.gateway
Ipv4.dns1
Ipv4.method
Manual

Network Interface Configuration TUI tool: Nmtui

Linux Learning notes--Network attribute management

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.