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

Theory: linux Network Services-linux Network Settings

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Configure routing, trace rout

Preface

View network settings

Test the network connection

Use the network configuration command

Modify network configuration file 1: view network interface information ifconfig1.1 view information of all active network interfaces execute ifconfig command 1.2 view specified network interface information [root@localhost ~] # ifconfig network interface name [root@localhost ~] # ifconfig ens33'ens33 first Ethernet card name': flags=4163 mtu 1500 'inet IP address 192.168.139.153' netmask subnet mask 255.255.255 .0' broadcast broadcast address 192.168.139.255 'inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 ether' 00:0c:29:d6:c0:8a MAC address' txqueuelen 1000 (Ethernet) RX packets 28803 bytes 2100162 (2.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 21495 bytes 3147424 (3.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

The name of the network card can be modified by ens33, and the time of modification is to modify the name of the network card when installing the system.

Two: view the host name hostname2.1 hostname command

View or set the current hostname

[root@localhost ~] # hostname 2.2 example [root@localhost ~] # hostname localhost hostname. 'localdomain means domain, and later mention' [root@localhost ~] # hostnamectl-- helphostnamectl [OPTIONS...] COMMAND... Query or change system hostname. -h-- help Show this help-- version Show package version-- no-ask-password Do not prompt for password-H-- host= [user @] HOST Operate on remote host-M-machine=CONTAINER Operate on local container-- transient Only set transient hostname-- static Only set static hostname-- pretty Only set pretty hostnameCommands: status Show Current hostname settings set-hostname NAME Set system hostname set-icon-name NAME Set icon name for host set-chassis NAME Set chassis type for host set-deployment NAME Set deployment environment for host set-location NAME Set location for host [root@localhost ~] # hostnamectl set-hostname gsy [root@localhost ~] # su [root@gsy ~] #

The second way to set the hostname is to modify the configuration file

/ etc/hostname configuration file

[root@gsy ~] # hostnamegsy [root@gsy ~] # vim / etc/sysconfig/network 'this configuration file is modified for centos 6 Does not apply to centos 7 routes # Created by anacondaHOST=mysql~ 3: view routing entries route3.1 route command View or set routing table information in the host route [- n]-n to display 3.2 example [root@965 ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.139.2 0.0.0.0 UG 10000 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 virbr0192.168.139.0 0.0.0.0 255.255.255.0 U 10000 ens33 [root@965 ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault gateway 0.0.0.0 UG 100 00 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 0 virbr0192.168.139.0 0.0.0.0 255.255.255.0 U 100 00 ens33

Destination segment Gateway gateway Genmask subnet mask metric metric

In centos 7, route differs from route-n in that the default network is changed to the number 0.0.0.0

In centos 6, the specific differences between route and route-n are shown as follows

[root@gsy ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.139.0 * 255.255.255.0 U 100 eth0default 192.168.139.2 0.0.0.0 UG 000 eth0 [root@gsy ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface192.168.139.0 0.0.0.0 255.255.255.0 U 1 00 eth00.0.0.0 192.168.139.2 0.0.0.0 UG 00 eth0 4: view the network connection netstat4.1 netstat command to view the network connection status of the system, Routing table, interface statistics, etc. Netstat [options] 4.2 Common options explain-a display all-n display serial numbers-p display port protocol-t display TCP protocol-u display UDP protocol-r display route description DESCRIPTION Netstat program displays information about the Linux network subsystem. The type of output information is controlled by the first parameter, like this: (none) when there is no option, netstat displays the open socket. If you do not specify any address families, print out valid sockets for all configured address families. -- route,-r displays the kernel routing table. -- groups,-g displays IGMP multicast group membership information for IPv4 and IPv6. -- interface=iface,-I displays a list of all network interfaces or a specified iface. -- masquerade,-M displays a list of all the disguised conversations. -- statistics,-s displays statistics for each protocol. The option OPTIONS-- verbose,-v runs in detailed mode. In particular, print some useful information about unconfigured address families. -- numeric,-n displays numeric addresses instead of parsing hosts, ports, or user names. Numeric-hosts displays the host in digital form but does not affect the resolution of the port or user name. -- numeric-ports displays the numeric port number, but does not affect the resolution of the host or user name. -- numeric-users displays the numeric user ID, but does not affect the resolution of host and port names. -- protocol=family,-A specifies the address families of which connections to display (perhaps better described in the underlying protocol). Family A comma-separated list of address families, such as inet, unix, ipx, ax25, netrom, and ddp. This has the same effect as using the-- inet,-- unix (- x),-- ipx,-- ax25,-- netrom, and-- ddp options. The address family inet includes raw, udp and tcp protocol sockets. -c,-- continuous will cause netstat to continuously output the selected information every second. -e,-- extend displays additional information. Use this option twice to get all the details. -o,-- timers contains information about network timers. -p,-- program displays the PID and name of the process to which the socket belongs. -l,-- listening displays only the sockets that are listening (this is the default option)-a,-- all displays all sockets that are or are not listening. Add the-- interfaces option to display untagged interfaces. -F displays routing information in FIB. (this is the default option)-C displays route information in the route buffer. Delay netstat loops out statistics every delay second. [root@965] # netstat-natpActive Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.0LISTEN 1117/cupsd tcp * LISTEN 1296/dnsmasq tcp 0 0 0.0.0.0 LISTEN 1117/cupsd tcp 22 0.0.0.0 LISTEN 1116/sshd tcp 0 127.0.1 00 127.0.0.1 LISTEN 1300/master tcp 25 0.0.0.0 * LISTEN 13953/sshd: root@pt tcp 0 36 192.168.139.153 root@pt tcp 22 192.168.139.1 : 64738 ESTABLISHED 13953/sshd: root@pt tcp6 0 0: 111: * LISTEN 1/systemd tcp6 0 0: 22:: * LISTEN 1116/sshd tcp6 0 0:: 1 LISTEN 1116/sshd tcp6 : * LISTEN 1117/cupsd tcp6 00:: 1:25: * LISTEN 1300/master tcp6 00:: 1 LISTEN 13953/sshd 6010: * LISTEN 13953/sshd: root@pt

Sshd refers to remote access

You can check it specifically with the search command.

[root@965 ~] # netstat-natp | grep "22" tcp 0 0192.168.122.1 tcp 53 0.0.0.0 LISTEN 1296/dnsmasq tcp 00 0.0.0.0 natp 22 0.0.0.0 tcp 0 36 192. 168.139.153root@965 22 192.168.139.1 ESTABLISHED 13953/sshd 64738 ESTABLISHED 13953/sshd: root@pt tcp6 0: 22: * LISTEN 1116/sshd [root@965 ~] # netstat-natp | grep sshtcp 00 0.0.0.0 root@965 22 0.0.0.0 root@965 * LISTEN 1116/sshd tcp 0 0 127.0.0.1 ESTABLISHED 13953/sshd 6010 0.0.0.0 LISTEN 13953/sshd: root@pt tcp 0 36 192.168.139.153 ESTABLISHED 13953/sshd: 22 192.168.139.1 ESTABLISHED 13953/sshd: 22: : * LISTEN 1116/sshd tcp6 0 0:: 1 root@pt 6010: * LISTEN 13953/sshd: root@pt [root@965 ~] # netstat-naup Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 192.168.139.153Viru 40345 192.168.139.2 Vol 53 ESTABLISHED 129301/hostname udp 0 0 0.0.0 0R 11836 0.0.0 0 * 7860/dhclient udp 0 0 0.0.0 v 44612 0.0.0 * 707/avahi-daemon: r udp 832 0 192.168.139.153 ESTABLISHED 124308/ssh udp 56951 192.168.139.2 ESTABLISHED 124308/ssh udp 0 192.168.122.1 ESTABLISHED 124308/ssh udp 53 0.0.0.0 1296/dnsmasq udp 00 0.0.0.015 0.0.0.0 * 1296/dnsmasq udp 0 0 0.0.0.015 68 0.0.0.015 * 7860/dhclient udp 0 00.0.0.015 5353 0.0.0.0 * 707/avahi-daemon: r udp 0 0 127.0.1 732/chronyd udp6 323 0.0.0.0 732/chronyd udp6 0 0:: 1 732/chronyd udp6 0 0: 49510:: * 7860/dhclient [root@965 ~] # netstat-naup | grep 22udp 0 0 192.168.122.1 grep 22udp 53 0.0.0.0 netstat * 1296/dnsmasq [root@965 ~] # netstat-rnKernel IP routing tableDestination Gateway Genmask Flags MSS Window irtt Iface0.0.0.0 192.168.139.2 0.0.0.0 UG 0 0 0 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0192.168.139.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33 [root@965 ~] # netstat-rKernel IP routing tableDestination Gateway Genmask Flags MSS Window irtt Ifacedefault gateway 0.0.0.0 UG 000 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 000 virbr0192.168.139.0 0.0.0.0 255.255.255.0 U 000 ens33 5: trace packet traceroute 5.1 traceroute command test network node traceroute target host address 5.2 experimental example from current host to destination host

Network card configuration in linux

[root@965 network-scripts] # vim / etc/sysconfig/network-scripts/ifcfg-ens33TYPE= "Ethernet" PROXY_METHOD= "none" BROWSER_ONLY= "no" BOOTPROTO= "dhcp" DEFROUTE= "yes" IPV4_FAILURE_FATAL= "no" IPV6INIT= "yes" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" IPV6_ADDR_GEN_MODE= "stable-privacy" NAME= "ens33" UUID= "0f432513-5d7a-455c-88b4-257a9a1dbb45" DEVICE= "ens33" ONBOOT= "yes" to TYPE= "Ethernet" PROXY_METHOD= "none" BROWSER_ONLY= "no" BOOTPROTO= "static" changes the original dhcp auto-assignment ip address protocol to a static protocol 'DEFROUTE= "yes" IPV4_FAILURE_FATAL= "no" IPV6INIT= "yes" IPV6_AUTOCONF= "yes" IPV6_DEFROUTE= "yes" IPV6_FAILURE_FATAL= "no" IPV6_ADDR_GEN_MODE= "stable-privacy" NAME= "ens33" UUID= "0f432513-5d7a-455c-88b4-257a9a1dbb45" DEVICE= "ens33" ONBOOT= "yes" IPADDR=192.168.10.10. The'ip address is 192.168.10.10'NETMASK=255.255.255.0 'subnet mask is 255.255.255.0'GATEWAY=192.168.10.1' gateway is 192.168.10.1':wq

Restart the network service after configuration

[root@965 network-scripts] # systemctl restart network [root@965 network-scripts] # service network restart Restarting network (via systemctl): [OK] [root@965 network-scripts] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255 inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) RX packets 121888 bytes 9724226 (9.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 161138 bytes 29666777 (MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

After the host1 is configured, configure host2 next

Then configure R1 and R2

R1#conf tEnter configuration commands, one per line. End with CNTL/Z.R1 (config) # int f0/0R1 (config-if) # ip add 192.168.10.1 255.255.255.0R1 (config-if) # no shut*Mar 1 00 LINEPROTO-5-UPDOWN 12 LINEPROTO-5-UPDOWN:% LINK-3-UPDOWN: Interface FastEthernet0/0:% LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0 Changed state to upR1 (config-if) # int f0/1R1 (config-if) # ip add 192.168.20.1 255.255.255.0R1 (config-if) # no shut*Mar 1 00 int f0/1R1 12 19. 323:% LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up*Mar 1 00 12 config-if:% LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1 Changed state to upR1 (config-if) # ip route 0.0.0.0 0.0.0.0 192.168.20.20R2#conf tEnter configuration commands, one per line. End with CNTL/Z.R2 (config) # int f0/0R2 (config-if) # ip add 192.168.20.20 255.255.255.0R2 (config-if) # no shutR2 (config-if) # int f0/1*Mar 100 12 LINK-3-UPDOWN: Interface FastEthernet0/0:% LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0 Changed state to upR2 (config-if) # ip add 192.168.30.1 255.255.255.0R2 (config-if) # no shutR2 (config-if) # ip route 0.0.0.0 0.0.0 192.168.20.1 [root@965 ~] # ping 192.168.30.30PING 192.168.30.30 (192.168.30.30) 56 (84) bytes of data.64 bytes from 192.168.30.30: icmp_seq=3 ttl=126 time=47.3 Ms64 bytes from 192.168.30.30: icmp_seq=4 ttl=126 time=43.7 ms64 bytes from 192.168.30.30: icmp_seq=5 ttl=126 time=43.4 ms64 bytes from 192.168.30.30: icmp_seq=6 ttl=126 time=42.4 Ms ^ C-192.168.30.30 ping statistics-6 packets transmitted 4 received, 33% packet loss, time 5013msrtt min/avg/max/mdev = 42.432 packet loss, 44.244 hops max 47.386 hops max, 1.881 hops max [root@965483 ~] # traceroute 192.168.30.30traceroute to 192.168.30.30 (192.168.30.30) 60 byte packets 1 gateway (192.168.10.1) 3.021 ms 12.829 ms 23.697 ms 2 192.168.20.20 (192.168.20.20) 33.630 ms 43.493 ms 54.322 ms 3 * 4 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 21 * 22 * 23 * 24 * 25 * 26 * 27 * 28 * 29 * 30 *

Enable the relevant configuration in server to realize the remote terminal link

The intermediate IP address is changed automatically, which should be adjusted in time.

Six: domain name resolution nslookup6.1 nslookup command test DNS command nslookup target host address [DNS server address] 6.2 example [root@localhost ~] # nslookup www.google.comServer: 192.168.139.2 'dns server address' Address: 192.168.139.2#53Non-authoritative answer: 'feedback resolution result' Name: www.google.comAddress: 74.86.226.234

Detection in windows

C:\ Users\ GSY > nslookup www.google.com server: ns.gwbnnj.net.cn 'DNS server address' Address: 211.162.31.80 non-authoritative answer: name: www.google.comAddresses: 2404ns.gwbnnj.net.cn 6800 ns.gwbnnj.net.cnAddress 2004 'ipv6 address' 74.86.226.234 'feedback result' C:\ Users\ GSY > nslookup www.taobao.com server: ns.gwbnnj.net.cnAddress: 211.162.31.80 non-authoritative response: name: www.taobao.com.danuoyi.tbcache.com 'taobao actual domain name' Addresses: 2409:8c28:2808:5:3::3fa 2409:8c28:801:3:3::3fa 2409:8c28:2808:5:3::3f9 2409:8c28:801:3:3::3f9 111.3.79.235 111.3. 79.234 211.138.124.237Aliases: www.taobao.com 'alias'

Server refers to DNS parsing server, followed by nj which means Nanjing.

The parsed address can be copied to the browser to access, Baidu can, but Taobao is not, this is because of the security protection, the dns server has also done the corresponding protection

7. Setting network parameters 7.1 temporary configuration-using commands to adjust network parameters is simple and fast, and can be directly modified. Running network parameters are generally only suitable for debugging the network after the system is rebooted. The modification will invalidate the fixed settings 7.2. The configuration file for modifying network parameters through the configuration file is suitable for setting fixed parameters on the server. When the network service needs to be reloaded or restarted, the configuration file will not take effect until it is restarted. 7.3 set network interface parameters command ifconfig

Set the IP address and subnet mask of the network interface

Ifconfig interface name (network card name) ip address [netmask subnet mask]

Ifconfig network interface ip address [/ mask length]

Disable or reactivate the network card

Ifconfig network interface up

Ifconfig network interface down

Set up a virtual network interface

Ifconfig API name: serial number IP address

API name ens33

[root@localhost ~] # ifconfig ens33: flags=4163 mtu 1500 inet 192.168.139.157'ip address' netmask 255.255.255.0 'subnet mask' broadcast 192.168.139.255 'broadcast address' inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) RX packets 4494 bytes 300077 (293.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 144bytes 15965 (15.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

Temporary modification, only for use with maintenance

Serial number, 0-123456, equivalent to logical interface

When a host needs to use multiple IP addresses, it can be configured using logical interfaces

[root@localhost ~] # ifconfig ens33 8.8.8.8 [root@localhost ~] # ifconfig ens33: flags=4163 mtu 1500 'inet 8.8.8.8 netmask 255.0.0.0 broadcast 8.255.255.255' inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) RX packets 4544 bytes 305199 (298.0 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 162 bytes 19317 (18.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] # ifconfigens33 8.8.8.8 Candle 24 [root@localhost ~] # ifconfigens33: flags=4163 mtu 1500 'inet 8.8.8 netmask 255.255.255.0 broadcast 8.8.255' inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 ether 00 : 0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) RX packets 4568 bytes 308317 (301.0 KiB) RX errors 0 dropped 0 overruns 0 TX packets 0 bytes 21475 (20.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] # ifconfigens33: 1 192.168.9.9 [root@localhost ~] # ifconfigens33: flags=4163 mtu 1500 inet 8.8.8 netmask 255.255.255 .0 broadcast 8.8.8.255 inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) RX packets 4663 bytes 315910 (308.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 197 bytes 25003 (24.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0ens33:1: flags=4163 mtu 1500 inet 192.168. 9.9 netmask 255.255.255.0 broadcast 192.168.9.255 ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) [root@localhost ~] # ifconfigens33: 1 down 'turn off ens33:1' [root@localhost ~] # ifconfigens33: flags=4163 mtu 1500 inet 8.8.8 netmask 255.255.255.0 broadcast 8.8.255 inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 Ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) RX packets 4683 bytes 317292 (309.8 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 203 bytes 25510 (24.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] # ifconfig ens33:1 up 'you can't find this address again. SIOCSIFFLAGS: unable to specify the requested address [root@ Localhost ~] # ifconfig ens33 down 'turn off the physical network card ens33' [root@localhost ~] # ifconfig lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback) RX packets 1672 bytes 144872 (141.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1672 bytes 144872 (141.4 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:e1:7d:d2 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] # ifconfigens33 up 'can successfully open' [root@localhost ~] # ifconfigens33: flags=4163 mtu 1500 inet 192.168.139.157 netmask 255.255.255.0 broadcast 192.168.139.255 inet6 fe80::413b:c9ad:e0e:1afc prefixlen 64 scopeid 0x20 ether 00:0c:29:d6:c0:8a txqueuelen 1000 (Ethernet) RX packets 4739 bytes 322970 (315.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 229 bytes 29270 (28.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

The down of logical subinterface (example: ens33:1) is equivalent to releasing the IP address.

8: set the routing record route8.1 add to the specified network segment route add-net network segment address gw IP address 8.2 delete the route record to the network segment route del-net network segment address gw IP address 8.3 delete the default gateway record route del defalut gw IP address 8.4 add the default gateway record route add default gw IP address to the routing table

Gw next hop address

-net target network segment

Destination Gateway Genmask Flags Metric Ref Use Iface'0.0.0.0 192.168.139.2 0.0.0.0 UG 1000 ens33 default gateway That is, it can be understood as the default route [root@localhost ~] # route add-net 192.168.10.0 gw 192.168.139.157SIOCADDRT: invalid parameter [root@localhost ~] # route add-net 192.168.10.0amp 24 gw 192.168.139.157 [root@localhost ~] # routeKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Ifacedefault gateway 0.0.0.0 UG 100 00 ens33'192.168.10.0 localhost.local 255.255.255.0 UG 00 0 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 0 virbr0192.168.139.0 0.0.0.0 255.255.255.0 U 100 00 ens33 [root @ localhost ~] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0.0.0 192.168.139.2 0.0.0.0 UG 1000 ens33192.168.10.0 192.168.139.157 255.255.255.0 UG 00 ens33192.168.122.0 0.0.0.0 255 .255.255.0 U 00 virbr0192.168.139.0 0.0.0.0 255.255.255.0 U 1000 ens33 [root@localhost ~] # route add-net 192.168.100.0amp 24 gw 192.168.139.157 [root@localhost] # route-nKernel IP routing tableDestination Gateway 'next hop' Genmask Flags Metric Ref Use Iface0.0.0 . 0 192.168.139.2 0.0.0.0 UG 100 00 ens33192.168.10.0 192.168.139.157 255.255.255.0 UG 00 0 ens33'192.168.100.0 192.168.139.157 255.255.255.0 UG 00 0 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 virbr0192.168.139.0 0.0.0.0 255.255.255.0 U 1000 ens33 [root@localhost] # route del-net 192.168.100.0 gw 192.168.139.157 [root@localhost] # route-nKernel IP routing tableDestination Gateway Genmask Flags Metric Ref Use Iface0.0. 0.0 192.168.139.2 0.0.0.0 UG 100 00 ens33192.168.10.0 192.168.139.157 255.255.255.0 UG 00 0 ens33192.168.122.0 0.0.0.0 255.255.255.0 U 00 0 virbr0192.168.139.0 0.0.0. 0 255.255.255.0 U 10000 ens33 Nine: modify hostname hostname9.1 hostname command set hostname

Hostname host name

9.2 example [root@localhost ~] # hostname gsy 'first method' [root@localhost ~] # su [root@gsy ~] # hostnamectl set-hostname hostname 'second method' [root@gsy ~] # su'or bash' [root@hostname ~] #

The third method: vim / etc/hostname modify the hostname, then save it, then shut down and restart

The fourth method: vim / etc/sysconfig/networkl changes the hostname, shuts down and restarts (not applicable to 7, applicable to 6)

Ifcfg-ens33: the configuration file of the first Ethernet card. [root@dabendan ~] # vim / etc/sysconfig/network-scripts/ifcfg-ens33TYPE= "Ethernet" type, Ethernet card 'PROXY_METHOD= "none' proxy method 'BROWSER_ONLY=" no "browser' BOOTPROTO=" dhcp "hire, ip address acquisition Dhcp gets' DEFROUTE= "yes' default route 'IPV4_FAILURE_FATAL=" no "' ipv4 failed verification no 'IPV6INIT=" yes "' ipv6 initialization on 'IPV6_AUTOCONF=" yes "' ipv6 automatic configuration on 'IPV6_DEFROUTE=" yes "' ipv6 default configuration on 'IPV6_FAILURE_FATAL=" no "ipv6 failed verification' IPV6_ADDR_GEN_MODE=" stable -privacy "'ipv6 address protocol mode V6 is stable private' NAME=" ens33 "'name' UUID=" 0f432513-5d7a-455c-88b4-257a9a1dbb45 "DEVICE=" ens33 "device 'ONBOOT=" yes "' when boot kernel starts' can be modified to static IP address network card BOOTPROTO=" static "'static acquisition' IPADDR= specified ip address NETMASK= specified subnet mask GAREWAY= specified gateway 10.2 restart network network service [root@localhost ~] # systemctl restart network10.3 disable network interface [root@localhost ~] # ifdown ens3310.4 enable network interface [root@localhost ~] # ifup ens3310.5 dual Nic configuration

1. Add a network card and automatically identify it (no reboot is required)

Disable and enable the network interface can also be modified in the configuration file, that is, the ONBOOT=no

11: configuration file 11.1 / etc/sysconfig/network hostname configuration file saves the global network configuration, including host information vim / etc/sysconfig/networkNETWORKING=yesHOSTNAME=chenggong:wqreboot 'restart takes effect'

This fourth method cannot be used in centos 7, but can be used in centos 6

11.2 / etc/resolv.conf Domain name Resolution profile to save this machine requires the IP address of the DNS server [root@dabendan ~] # vim / etc/resolv.conf# Generated by NetworkManagersearch localdomain' host domain 'nameserver 192.168.139.2' default gateway You can also manually configure the '11.3 / etc/hosts local host mapping file to save the hostname and IP address mapping file [root@dabendan ~] # vim / etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6119.75.218.70 www.baidu.comhosts file and DNS server comparison by default First of all, the system finds the parsing record from the hosts file. The hosts file is only valid for the current host hosts file, which reduces the DNS query process, thus speeding up the access speed.

Domain name resolution will first check the / etc/hosts mapping file. If not, it will go to the dns server again.

The location of the hosts file in windows

Twelve: summary:

View network configuration

Ifconfig 、 hostname 、 route 、 netstat

Test the network connection

Ping 、 traceroute 、 nslookup

Set network address parameters

Temporary configuration, permanent configuration

Related configuration files

/ etc/sysconfig/network hostname profile

/ etc/resolv.conf domain name resolution profile

/ etc/hosts mapping file

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

Servers

Wechat

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

12
Report