linux网络配置

网络设定

学习目标

  1. 知道查看网络信息的基础命令
  2. 能够手动配置网络信息

1、手动设定

手动设定的ip,也叫做静态ip地址。手动设定ip,必须取得下面的几个参数才能够让系统联网:

  • IP
  • 子网掩码
  • 网关(gateway)
  • DNS主机IP

查看网卡配置项

第一种方式:网卡配置文件所在目录:/etc/sysconfig/network-scripts/

[root@itcast network-scripts]# cd /etc/sysconfig/network-scripts/
[root@itcast network-scripts]# cat ifcfg-eno16777736 
HWADDR="00:0C:29:17:6E:52"	// 硬件地址,mac地址
TYPE="Ethernet"				// 网络类型
BOOTPROTO="dhcp"			// 地址分配方式
...省略...
NAME="eno16777736"			//设备名称
UUID="cad73489-0b2e-46af-bc13-d281d6577606"
ONBOOT="yes"				//是否开机启动

第二种方式:命令方式:nmcli connection show 网卡名称

[root@itcast network-scripts]# nmcli device show eno16777736 
connection.id:                          eno16777736
connection.uuid:                        cad73489-0b2e-46af-bc13-d281d6577606
connection.interface-name:              --
connection.type:                        802-3-ethernet
connection.autoconnect:                 yes
...省略...
ipv4.method:                            auto
ipv4.dns:                               
ipv4.dns-search:                        
ipv4.addresses:                         
ipv4.routes:                            
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
...省略...

含义:

配置项 说明
connection.autoconnect [yes|no] 是否开机时启动网络,预设同时是yes
ipv4.method [auto|manual] 自动还是手动设定网络参数
ipv4.dns dns地址
ipv4.addresses ip地址

配置网络

# 查看当前网卡数据,由于我们没有静态ip地址,所以使用自动获取的地址信息作为静态ip地址。
[root@itcast network-scripts]# nmcli device show eno16777736
# 配置操作
[root@itcast html]# nmcli connection modify eno16777736                         
> connection.autoconnect yes                                                    
> ipv4.method nanual                                                            
> ipvr.addresses 172.16.99.248/24                                               
> ipv4.gateway 172.16.99.2                                                      
> ipv4.dns 172.16.99.2    

[root@itcast html]# nmcli connection up eno16777736     # 使网络生效
[root@itcast html]# nmcli connection show eno16777736   # 查看配置状态

2、DHCP自动获取

[root@itcast html]# ncmli connection modify en016777736                         
> connection.autoconnect yes                                                    
> ipv4.method auto    

[root@itcast html]# nmcli connection up eno16777736     # 使网络生效
[root@itcast html]# nmcli connection show eno16777736   # 查看配置状态

所有的事都会过去,我们所有的人都是从小白开始,坚持下去。
原文地址:https://www.cnblogs.com/li-dy/p/12012051.html