Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

Before we understand the basic Linux system administration commands and techniques, in order to further learning Linux network services to lay a foundation, and this time I will share with you several points:

  1. View network settings
  2. Testing Network Connectivity
  3. Use network configuration commands
  4. Modify the network configuration file

    The example experiment operating environment we need to prepare is:
    1, VMware virtual machines (which had installed two CentOS 7 client)
    2, XSell remote connection terminals (two in advance and clients to connect)

1. Check the network interface information ifconfig:

View all active network interfaces information
execute ifconfig command
to view the information specified network interface: ifconfig network interface name

Example: [root @ localhost ~] #ifconfig ens33, may be displayed
on a card name: ens33
the IP address: 192.168.56.128
Subnet Mask: 255.255.255.0
the MAC Address: 00: 0c: 29: b9 : fc: 25
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

2. Check the host name hostname:

View or set the current host name: hostname

Example: br /> Input: [root @ localhost ~] #hostname ( host name currently displayed)
Display: localhost.
Input: hostnamectl set-hostname web01 (modified host name)
Input: su (bash environment switching force)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

3. Check the routing table entry route:

route command
to view or set the host routing table: route [-n]
Example:

Input: route -n (see routing table)
can be seen: the target network segment IP, gateway, subnet mask these important information
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

4. Check the network connection netstat:

netstat command:
View system network connection status, routing tables, interface statistics and other information: netstat [options]

Common options:
a: represents all
n: that represented in digital form
t: the representative of TCP
p: indicates the protocol
u: UDP representatives
r: Specifies routing
Example:
Input: ntstat -ntap (see TCP protocol)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
Input: ntstat -nuap (see UDP protocol)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
Input: netstat -r (routing table)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

5. Test network connections ping:

Test network connectivity: ping [Option] target host
1. In the system default windows made four test package
2. In the Linux system is the default length measurement, needs to be terminated in order to press Ctrl + c

Examples :( Linux system)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

6. DNS nslookup:

nslookup command
test DNS name resolution: nslookup target host address [DNS Server Address]
wherein: port 53 using UDP protocol (analytical) using a TCP protocol (connection)

Example:
In the case of confirmation host networking can open the pages of
input: nslookup www.baidu.com(domain name address resolution for this)
get: 182.61.200.7 (copy this IP address into the browser also can open Baidu pages)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

7. The network parameters set by:

临时配置——使用命令调整网络参数:
1、简单、快递,可直接修改运行中的网络参数
2、一般只适合在调试网络的过程中使用
3、系统重启以后,所做的修改将会失效

临时修改命令如下:
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

固定设置——通过配置文件修改网络参数:
1、修改各项网络参数的配置文件
2、适合对服务器设置固定参数时使用
3、需要重载网络服务或者重启以后才会生效

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

8.设置网络接口参数ifconfig:

设置网络接口的IP地址、子网掩码
格式1:ifconfig 接口名 ip地址 [netmask 子网掩码]
格式2:ifconfig 网络接口 ip地址 [/掩码长度]
禁用或者重新激活网卡
格式1:ifconfig 网络接口 up
格式2:ifconfig 网络接口 down
操作实例(需在CentOS终端操作):
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
设置虚拟网络接口
格式:ifconfig 接口名序号 IP地址
设置虚拟网卡示例:
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

9.设置路由记录route:

添加到指定网段的路由记录:
格式:route add -net 网段地址 gw IP地址
删除到指定网段的路由记录:
格式:route del -net 网段地址
操作实例:
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
删除路由表中的默认网关记录:
格式:route del default gw IP地址
向路由表中添加默认网关记录:
格式:route add default gw IP地址
操作实例:
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

10.网络接口配置文件:

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

操作如下:
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

11.建立双网卡:

linux作为路由交换、代理服务器、防火墙规则(需要用到双网卡
2U的服务器网络接口有4个
实验如下:

虚拟机中设置,添加网络适配器
需要添加第二个网络适配器:
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
输入:ifconfig(此时能看到新添加的网卡,而且vmnet用dhcp服务自动分配了IP地址)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
输入:cd /etc/sysconfig/network-scripts/(查看新增加的ens36网卡,此时是没有的)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
设置两个网卡为仅主机模式,此时两块网卡都没有IP地址:
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
接下来先对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 of command, to create a conscience, you deserve !!!)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
输入:cd /etc/sysconfig/network-scripts/
输入:ls(查看详细信息,此时是没有ens36网卡的配置文件的)
输入:cp -p ifcfg-ens33 ifcfg-eds36(复制配置文件给ens36)
输入:ls(此时ens36就有了网卡配置文件)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
但是此时是不可以直接使用的,因为里面的配置信息为网卡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 of command, to create a conscience, you deserve !!!)
输入:systemctl restart network(重启网络服务)
输入:ifconfig(此时可以看到ens36的IP配置成功)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
以上就是配置双网卡的实验。

12.域名解析配置文件:

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

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

13.本地主机映射文件:

/etc/hosts文件
保存主机名与IP地址的映射记录

hosts文件和DNS服务器的比较

1、默认情况下,系统首先从hosts文件查找解析记录
2、hosts文件只对当前的主机有效
3、hosts文件可减少DNS查询过程,从而加快访问速度
解析示例:
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
缺点是:当主机比较多的时候需要逐个更改hosts文件配置

扩展知识(福利走一波):

1、本地文件同步到其他服务器:
格式:scp 本地文件路径 用户@ip:远程服务器文件路径
示例:

例如CentOS 7-1中的hosts配置文件中我们写入的内容比较多我们想要同步到另外一台服务器上,此时我们需要做的步骤如下:
打开:CentOS 7-2终端
输入:cat /etc/hosts(此时没有同步只能看到初始的两条内容)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
在CentOS 7-1终端中
输入:cat /etc/hosts(可以看到除了初始的两条内容之外还有额外添加的三条内容)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
输入:scp /etc/hosts [email protected]:/etcc/hosts(同步本地文件到其它服务器)
输入:yes(确认同步)
输入:123123(此处为对方的用户密码)
最终文件同步到其它服务器成功
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
我们回到CentOS 7-2终端中进行验证
输入:cat /etc/hosts(可以看到三条内容成功同步到其中)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

2、对方服务器文件同步到本地:
格式:scp 用户@ip:远程服务器文件路径 本地同步文件路径
示例:

Input: vim / etc / hosts (add a new content)
enter: wq (save and exit)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
At this point we switched to CentOS 7-2 terminal to the other file server is synchronized to the local
input: scp [email protected]: / etc / hosts / etc / hosts
inputs: 123123 (counterpart account password)
at this time to see the successful synchronization
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)
input: cat / etc / hosts (you can see a successful sync content to add to it)
Linux Network Services (thorough explanation of command, to create a conscience, you deserve !!!)

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/14464303/2433479