Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How much do you know about Linux network management?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

I. basic network configuration

1. Configure the network

2. Implement the network group

3. Test the network

4. Network tools

II. Network configuration

1) static assignment

Ifcfg:ifconfig,route,netstat ip:object {link,addr,route}, ss,setup

New utility for centos7: nmcli nmtui

2) dynamic allocation

DHCP: Dynamic Host Configuration Protocol

Ifconfig command:

Ifconfig [interface]

Ifconfig-a # displays all network card information

Ifconfig {eth0 | eth2} [up | down] # close or enable a network card

Ifconfig interface [aftype] options | address...

Ifconfig IFACE IP/mask [up] # temporarily add an ip address such as: ifconfig eth0:0 10.1.1.1Pax 16

Ifconfig IFACE IP netmask MASK # temporarily add an ip address such as ifconfig eth0:0 10.1.1.1 255.255.0.0

Note: this order takes effect immediately

Code demonstration:

Root@centos6 ~] # ifconfig eth2eth2 Link encap:Ethernet HWaddr 00:0C:29:7C:55:97 inet addr:192.168.226.133 Bcast:192.168.226.255 Mask:255.255.255.0 BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:2922 errors:0 dropped:0 overruns:0 frame:0 TX packets:726 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:201495 (196.7 KiB) TX bytes:71868 (70.1 KiB) [root@centos6] # ifconfig eth2 down [root@centos6] # ifconfig eth2 up [root@centos6] # ifconfig eth0:1eth0:1 Link encap:Ethernet HWaddr 00:0C:29:7C:55:8D inet addr:10.1.1.2 Bcast:10.1.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 [root@centos6] #

Common commands for network configuration

Route command:

View routes: route-n

Add Route: route add

Route add [- net |-host] target [netmask Nm] [gw Gw] [[dev] If]

Example: route add-net 192.168.1.10 gw 24 gw 10.1.0.1 dev eth0

Route add-net 192.168.0.2 netmask 255.255.255.0 gw 172.16.0.1 dev eth0

Route add-net 192.168.0.2 hand 24 gw 172.16.0.1 dev eth0

Default route: route add-net 0.0.0.2 netmask 0.0.0.0 gw 172.16.0.1

Route add default gw 172.16.0.1

Delete route: route del

Route del 192.168.1.3

Route del-net 192.168.0.1 netmask 255.255.255.0

Demo:

[root@centos7 ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 10.1.249.1 0.0.0.0 UG 10000 eth00.0.0.0 192.168.226.2 0.0.0.0 UG 101 00 eth210.1.0.0 0 .0.0.0 255.255.0.0 U 10000 eth0192.168.226.0 0.0.0.0 255.255.255.0 U 10000 eth2 [root@centos7 ~] # route add-net 192.168.12.0 route 24 gw 10.1.249.1 [root@centos7 ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 10.1.249.1 0.0.0.0 UG 100 00 eth00.0.0.0 192.168.226.2 0.0.0.0 UG 101 00 eth210.1.0.0 0.0.0.0 255.255.0.0 U 100 0 0 eth0192.168.12.0 10.1.249.1 255.255.255.0 UG 00 0 eth0192.168.226.0 0.0.0.0 255.255.255.0 U 10000 eth2 [root@centos7] # route add-host 10.1.250.1 gw 10.1.249.1 [root@centos7] # route add-host 10.1.24. 23 gw 10.1.0.1 [root@centos7 ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 10.1.249.1 0.0.0.0 UG 10000 eth00.0.0.0 192.168.226.2 0.0.0.0 UG 10100eth210. 1.0.0 0.0.0.0 255.255.0.0 U 100 00 eth010.1.24.23 10.1.0.1 255.255.255.255 UGH 00 0 eth010.1.250.1 10.1.249.1 255.255.255.255 UGH 00 0 eth0192.168.12.0 10.1 .249.1 255.255.255.0 UG 00 eth0192.168.226.0 0.0.0.0 255.255.255.0 U 10000 eth2 [root@centos7 ~] # route del-net 192.168.12.0 netmask 255.255.255.0 [root@centos7] # route del-host 10.1.24.23 [root@centos7] # route del-host 10.1 .250.1 [root@centos7 ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 10.1.249.1 0.0.0.0 UG 1000 eth00.0.0.0 192.168.226.2 0.0.0.0 UG 10100 eth210.1.0.0 0.0.0.0 255.255.0.0 U 10000 eth0192.168.226.0 0.0.0.0 255.255.255.0 U 10000 eth2 [root@centos7 ~] #

Netstat command:

Netstat-Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships

Options:

-related to t:tcp protocol

-related to u:udp protocol

-w:raw socket

-l: listen in listening state

-a: all statu

-n: display ip and port in numbers

-e: extended format

-p: displays related processes and their pid

Common combinations:-tan,-uan,-tnl,-unl

Ss command:

Ss [OPTION]... [FILTER]

Netstat traverses proc to get socket information, and ss uses netlink to communicate with kernel tcp_diag module to obtain socket information, which is more efficient than netstat.

Options:

-t:tcp related protocols

-related to u:udp protocol

-x:unix sock related

-l:listen snooping statu

-a: all

-n: numeric format

-p: related programs and pid

-e: extended information

-m: memory information

Ip command:

Configure linux network properties: ip-show / manipulate routing, devices, policy routing and tunnels

Ip link-network device configuration

Set dev IFACE such as: ip link set dev eth0 up/down

Ip addr {add | del} IFADDR dev STRING [label LABEL]

Ip address flush # clear ip address ip address flush dev eth0

Ip addr add 192.168.100.1 Universe 24 dev eth0 label eth2:1 # add a temporary ip address

Ip addr del 172.16.100.13 dev eth0 label eth0:0 16 delete the temporarily added ip address

Ip addr flush dev eth0 label eth0:0 # Delete the ip record of eth0

Ip route-routing table management

Add Route: ip route add

Ip route add TARGET via GW dev IFACE src SOURCE_IP

Ip route add 192.168.0.0/24 via 172.16.0.1

Ip route add 192.168.1.2 via 172.16.0.1

Delete route: ip route delete target

Show route: ip route show | list

Clear the route: ip route flush # ip route flush dev eth0

IV. Network profile

1) configuration files related to IP, MASK, GW, DNS: / etc/sysconfig/network-scripts/ifcfg-IFACE

2) routing-related configuration file: / etc/sysconfig/network-scripts/route-IFACE

/ etc/sysconfig/network-scripts/ifcfg-IFACE: the configuration file is described as follows

DEVICE: the device to which this profile is applied

BOOTPROTO: {staic | dhcp | none} address configuration protocol used when activating this device

ONBOOT: whether to activate this device when the system boots

TYPE: interface typ

UUID: unique identification of the device

HWADDR:mac address

IPADDR: indicates the IP address

NETMASK: subnet mask

GATEWAY: default gateway

DNS1: the first DNS server points to

DNS2: the second DNS server points to

PEERDNS: if the value of BOOTPROTO is "dhcp", whether to allow the dns server point information assigned by dhcp server to be overwritten directly into the / etc/resolv.conf file

3) Local parser

The parser performs forward and reverse queries: / etc/hosts images of the local hostname database and IP addresses are useful for small stand-alone networks. Usually, check before using DNS

Getent hosts # View / etc/hosts content

4) dns domain name resolution: / etc/resolv.conf

Nameserver dns_server_ip1

Nameserver dns_server_ip2

Nameserver dns_server_ip3

Configure local resolution and domain name resolution priority: / etc/nsswitch.conf

5) Network card alias

Ifconfig command: ifconfig eth0:0 192.168.1.100 Compact 24 up

Ip command:

Ip addr add 192.168.1.2/24 dev eth0

Ip addr add 192.168.1.3/24 dev eth0 label eth0:0

Ip addr del 192.168.1.3/24 dev eth0 label eth0:0

Ip addr flush dev eth0 label eth0:0

6) configure hostname

Tui (text user interface) of Linux network attribute configuration: system-config-network-tui setup Note: remember to restart the network service to take effect

Configure the hostname of the current host: hostname [HOSTNAME] / etc/sysconfig/network HOSTNAME=

7) name of the network card

The network interface identifies and names the relevant udev configuration files

/ etc/udev/rules.d/70-persistent-net.rules unload Nic driver: modprobe-r e1000 load Nic driver: modprobe e1000 (centos6.x)

# PCI device 0x8086:0x100f (E1000) SUBSYSTEM== "net", ACTION== "add", DRIVERS== "? *", ATTR {address} = = "00:0c:29:7c:55:97", ATTR {type} = = "1", KERNEL== "eth*", NAME= "eth2" # PCI device 0x8086:0x100f (e1000) (custom name provided by external tool) SUBSYSTEM== "net", ACTION== "add", DRIVERS== "? *", ATTR {address} = = "00:0c:29:7c:55:8d", ATTR {type} = "1", KERNEL== "eth*" NAME= "eth0"

Use traditional naming: use eth0,1,2... in centos7.x Indicates that / etc/boot/grub2/grub.cfg configuration file can be modified

Fifth, network customer service tools

1) File transfer tool and its download tool

Lftp, ftp, lftpget, wget

Lftp [- p port] [- u user [, password]] SERVER

Subcommands: get, mget, ls, help

2) lftpget URL # lftp 192.168.1.1

3) wget [option]... [URL]...

-Q: silent mode

-c: resume transmission from breakpoint

-O: save location

-- limit-rates=: specifies the transfer rate

Such as: wget ftp://10.1.0.1/pub/alren/xiaoerduowget

Http://www.xiaoerduo/pub/alren/xiaoerduo

This article is from the original small ear, some simple repetitive commands do not want to show too much, if you want to master it skillfully, you need to practice.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report