Linux Network Management

Source: Internet
Author: User
Tags nameserver

How to configure:

Statically specified:

Ifcfg:ifconfig, Route, Netstat

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

Configuration file:

System-config-network-tui (Setup)

CentOS 7:nmcli, Nmtui

Dynamic allocation:

Dhcp:dynamic Host Configuration Protocol


CentOS 6 Configuration network:

Interface Naming method:

Ethernet: eth[0,1,2,...]

ppp:ppp[0,1,2,...]

Ifconfig command

Ifconfig [Interface]

# ifconfig-a

# ifconfig IFACE [Up|down]

Ifconfig interface [Aftype] options | Address ...

# ifconfig IFACE Ip/mask [up]

# ifconfig IFACE IP netmask MASK

Note: Immediate effect

Enable promiscuous mode: [-]promisc

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: 172.16.0.1

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

Target: 192.168.0.0 Gateway: 172.16.0.1

~]# Route add-net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 Dev eth0

~]# Route add-net 192.168.0.0/24 GW 172.16.0.1 Dev eth0

Default route, Gateway: 172.16.0.1

~]# Route add-net 0.0.0.0 netmask 0.0.0.0 GW 172.16.0.1

~]# route add default GW 172.16.0.1

Delete: Route del

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

Target: 192.168.1.3 Gateway: 172.16.0.1

~]# Route Del-host 192.168.1.3

Target: 192.168.0.0 Gateway: 172.16.0.1

~]# Route del-net 192.168.0.0 netmask 255.255.255.0


The DNS server specifies:

/etc/resolv.conf

NameServer DNS_SERVER_IP1

NameServer DNS_SERVER_IP2

NameServer DNS_SERVER_IP3


Netstat command:

Netstat-print network connections, routing tables, interface statistics, masquerade connections, and multicast Membershi Ps

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: Digital display of IP and ports

-E: Extended format

-P: Show related processes and PID

Common combinations:

-tan,-uan,-TNL,-UNL

Show route table:

netstat {--route|-r} [--numeric|-n]

-R: Show kernel routing table

-N: Number format

Display Interface Statistics:

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

# netstat-i

# netstat-i IFACE



CentOS 7 Configuration network:

IP command:

Ip-show/manipulate routing, devices, policy Routing and tunnels

IP [OPTIONS] OBJECT {COMMAND | help}

OBJECT: = {link | addr | route}


Link OBJECT:

IP link-network Device Configuration

Set

Dev IFACE: can set properties

Up and down: Activates or disables the specified interface

Show

[Dev IFACE]: Specify interface

[Up]: Show only interfaces that are in the active state


IP Address-protocol Address Management

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 available

Host: This machine is available

[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-routing Table Management

IP route add

Add route: IP route add TARGET via GW dev IFACE src source_ip

Add Gateway: IP route add defalt via GW Dev IFACE

IP route Delete

Delete route: IP route del TARGET

IP Route Show

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 information

FILTER: = [State Tcp-state] [EXPRESSION]

Common State of TCP:

TCP Finite state machine:

LISTEN, established, Fin_wait_1, Fin_wait_2, Syn_sent, SYN_RECV, CLOSED

EXPRESSION:

Dport =

Sport =

Example: ' (Dport =: ssh or sport =: SSH) '


To modify a configuration file:

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: MAC address of the corresponding device

Bootproto: Address configuration protocol used when activating this device, common DHCP, static, none, BOOTP

NM_CONTROLLED:NM is a shorthand for NetworkManager; 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: Unique identification of the device

IPADDR: Specify IP Address

NETMASK: Subnet Mask

Gateway: Default Gateways

DNS1: The first DNS server points to a

DNS2: The second DNS server points to a

Userctl: Whether a normal user can control this device

Peerdns: If the value of Bootproto is "DHCP", whether to allow DHCP server to assign a DNS server to direct the information to overwrite 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


Configure multiple addresses for the NIC:

Ifconfig:ifconfig Iface_alias

Ip:ip addr Add

Configuration file:

Ifcfg-iface_alias

Device=iface_alias

Note: Gateway aliases cannot be booted with the DHCP protocol


Configuration of the Linux Network properties TUI (text user interface):

System-config-network-tui

You can also use Setup to find

Note: Remember to restart the network service before it takes effect


To configure the host name of the current host:

hostname [hostname]

/etc/sysconfig/network


The network interface identifies and names the associated udev configuration files:

/etc/udev/rules.d/70-persistent-net.rules


To uninstall the NIC driver:

Modprobe-r e1000

Load NIC driver:

Modprobe e1000


CentOS 7 Network Properties configuration:

Traditional naming: Ethernet eth[0,1,2,...], wlan[0,1,2,...]

Predictable features:

Udev supports a number of different naming schemes: Firmware, topological structure

(1) network card naming mechanism

Systemd How to name a network device:

(a) If the index information provided by the firmware or BIOS-integrated device on the main board is available and predictable, it is named according to this index, for example Eno1

(b) If the index information provided by the firmware or BIOS for the PCI-E expansion slot is available and predictable, it is named according to this index, such as ens1;

(c) If the physical location information for the hardware interface is available, it is named according to this information, such as Enp2s0

(d) If the user is explicitly started, it can also be named according to the MAC address, enx2387a1dc56

(e) When none of the above is available, use the traditional naming mechanism

Note: Some of the above naming schemes require the participation of biosdevname programs.

(2) Name composition format

En:ethernet

Wl:wlan

Ww:wwan

Name Type:

O<INDEX>: Device index number for integrated devices

S<slot>: index number of the expansion slot

X<MAC>: MAC Address-based naming

P<bus>s<slot>: enp2s1


The naming process for the network card device:

The first step:

Udev, Assistant utility/lib/udev/rename_device,/usr/lib/udev/rules.d/60-net.rules

Step Two:

Biosdevname will be based on/usr/lib/udev/rules.d/71-biosdevname.rules

Step Three:

By detecting network interface devices, according to/usr/lib/udev/rules.d/75-net-description

Id_net_name_onboard, Id_net_name_slot, Id_net_name_path


Return to the traditional naming method:

(1) Editing the/etc/default/grub configuration file

grub_cmdline_linux= "Net.ifnames=0 rhgb quiet"

(2) generate its configuration file for Grub2

Grub2-mkconfig-o/etc/grub2.cfg

(3) Rebooting the system


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.dns

Ipv4.method

Network Interface Configuration TUI tool: Nmtui

Host name Configuration tool: Hostnamectl

Status

Set-hostname

This article is from the "Ricky Technology Blog" blog, make sure to keep this source http://r1cky.blog.51cto.com/10646564/1773860

Linux Network 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.