Linux Network Services (thorough explanation)

Benpian structure:

Check the network configuration
to test the network connection
settings network address parameters
established dual card

First, view the network configuration

View all active network interface information

As we all know, the Internet needs network card. In the Microsoft environment, you can use the ipconfig command to view the IP address of the device, but in a Linux environment, use:

// ifconfig command to view information on the computer network equipment

Linux Network Services (thorough explanation)
among them,

ens33-- card name for the device, with a PC card functions the same
lo-- loopback adapter (NIC dedicated to self-test to detect whether TCP services on-line)
virbr0-- virtual bridged LAN

View and edit hostname

Check the host name
using the "hostname" command to view the host name

[root@localhost ~]# hostname

Linux Network Services (thorough explanation)
Modify the host name
in the format:

[root@localhost ~]# hostnamectl set-hostname local1

Which, "local1" to new host name. Then use the "su" command to refresh the entry into force of the new hostname
Linux Network Services (thorough explanation)

View device routing table

Using the "route" command to view

route -n // View Host Routing Table Information

Diagram:
Linux Network Services (thorough explanation)
wherein,

"Destination" - corresponding to a target network address
"Gateway" - corresponding to the next hop address
"Iface" - corresponding to the transmission data network interface

View network connections

Use "netstat" command

netstat [options] // Check System network connection status, interface statistics and other information

Its common options:

-a-- displays all
-n-- digitally display
-p-- representation agreement
-t-- represent TCP
-u-- expressed UDP
-r-- represent routing table information

Illustration:
Display all TCP services online

[root@localhost ~]# netstat -atnp

Linux Network Services (thorough explanation)
Show all the online services of UDP

[root@localhost ~]# netstat -aunp

Linux Network Services (thorough explanation)
Second, testing network connections

Test-Fi

ping [选项] 目标主机 //测试网络连通性

示意图:
Linux Network Services (thorough explanation)

域名解析

使用“nslookup”命令

nslookup 目标主机地址 [DNS服务器地址] //测试DNS域名解析

示意图:
测试解析百度的域名
Linux Network Services (thorough explanation)
三、设置网络地址参数

临时配置——使用命令调整网络参数

  • 简单、快速,可直接修改运行中的网络参数
  • 一般只适合在调试网络的过程中使用
  • 重启后,所有修改失效

    格式:ifconfig 接口名IP地址

临时修改命令如下:
Linux Network Services (thorough explanation)

固定设置——通过配置文件修改参数

  • 修改网络参数的配置文件
  • 适合对服务器设置固定参数时使用
  • 需要重载网络服务或者重启以后才会生效

永久修改示例:
输入:vim /etc/sysconfig/network-scripts/ifcfg-ens33(进入修改配置)
将dhcp改为static
在末行按o在下一行插入:IPADDR地址、NETMASK子网掩码、GETWAY网关
输入:wq(保存退出即可修改成功)
Linux Network Services (thorough explanation)
Linux Network Services (thorough explanation)
Linux Network Services (thorough explanation)

设置网络接口参数

设置网络接口的IP地址、子网掩码

格式1:ifconfig 接口名 ip地址 [netmask 子网掩码]
格式2:ifconfig 网络接口 ip地址 [/掩码长度]

禁用或者重新激活网卡

格式1:ifconfig 网络接口 up(ifup 网络接口)——两种皆可
格式2:ifconfig 网络接口 down(idown 网络接口)——两种皆可

操作实例(需在CentOS终端操作):
Linux Network Services (thorough explanation)
Linux Network Services (thorough explanation)

设置虚拟网络接口

格式:ifconfig 接口名序号 IP地址

设置虚拟网卡示例:
Linux Network Services (thorough explanation)

设置路由记录

添加到指定网段的路由记录:

格式:route add -net 网段地址 gw IP地址

删除到指定网段的路由记录:

格式:route del -net 网段地址

操作实例:
Linux Network Services (thorough explanation)

删除路由表中的默认网关记录:

格式:route del default gw IP地址

向路由表中添加默认网关记录:

格式:route add default gw IP地址

操作实例:
Linux Network Services (thorough explanation)

网络接口配置文件:

此配置文件在:/etc/sysconfig/network-scripts/目录下
例:ifcfg-ens33为第一块以太网卡的配置文件

操作如下:
Linux Network Services (thorough explanation)

四、建立双网卡
linux作为路由交换、代理服务器、防火墙规则(需要用到双网卡)
2U的服务器网络接口有4个

实验如下:
虚拟机中设置,添加网络适配器
需要添加第二个网络适配器:
Linux Network Services (thorough explanation)
输入:ifconfig(此时能看到新添加的网卡,而且vmnet用dhcp服务自动分配了IP地址)
Linux Network Services (thorough explanation)
输入:cd /etc/sysconfig/network-scripts/(查看新增加的ens36网卡,此时是没有的)
Linux Network Services (thorough explanation)
设置两个网卡为仅主机模式,此时两块网卡都没有IP地址:
Linux Network Services (thorough explanation)
Linux Network Services (thorough explanation)
接下来先对ens33配置地址:
输入:vim /etc.sysconfig/network-scripts/ifcfg-ens33(进入修改网卡配置)
修改dhcp为static
到末行按o转下一行
输入:IPADDR=192.168.10.10(配置IP),转下一行
输入:NETMASK=255.255.255.0(配置子网掩码),转下一行
输入:GETWAY:192.168.10.0(配置网关)
按Esc退出插入模式
输入:wq(保存退出)
输入:service network restart(重启网络配置)
输入:ifconfig(此时能看到ens33的IP地址为192.168.10.10)
Linux Network Services (thorough explanation)
Linux Network Services (thorough explanation)

输入:cd /etc/sysconfig/network-scripts/
输入:ls(查看详细信息,此时是没有ens36网卡的配置文件的)
输入:cp -p ifcfg-ens33 ifcfg-eds36(复制配置文件给ens36)
输入:ls(此时ens36就有了网卡配置文件)
Linux Network Services (thorough explanation)
但是此时是不可以直接使用的,因为里面的配置信息为网卡ens33的信息,所以我们需要对其进行修改!(此处需要注意的是,在配置之前需要先复制ens36的MAC地址:00:0c:29:b9:fc:2f)
两处ens33改ens36
修改UUID需不相同,光标到UUID行按dd删除
输入:IPADDR=192.168.20.20
输入:NETMASK=255.255.255.0
输入:GETWAY:192.168.20.0
输入:wq(保存退出)
Linux Network Services (thorough explanation)

输入:systemctl restart network(重启网络服务)
输入:ifconfig(此时可以看到ens36的IP配置成功)
Linux Network Services (thorough explanation)
以上就是配置双网卡的实验。

域名解析配置文件:

文件位置:/etc/resolv.conf
保存本机需要使用的DNS服务器的IP地址

[root@localhost~]#vi /etc/resolv.conf
search localdomain
nameserver 202.106.0.20
nameserver 202.106.148.1

本地主机映射文件:

/ etc / hosts file
to save the host name and IP address mapping records
compare the hosts file and DNS servers

1, by default, the system first looks from the hosts file parsing record
2, hosts file is only valid for the current host
3, hosts file can reduce DNS query process, thus speeding up access speed
parsing example:
Linux Network Services (thorough explanation)
drawback is: when relatively large number of hosts when You need to individually change the hosts file configuration

These are the theoretical and experimental operation Linux network settings, thank you Tell me what you watch, you can also follow the operation steps, thank you support!

Guess you like

Origin blog.51cto.com/14484404/2433508