学习目标

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

1、手动设定

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

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

查看网卡配置项

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

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

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

  1. [root@itcast network-scripts]# nmcli device show eno16777736
  2. connection.id: eno16777736
  3. connection.uuid: cad73489-0b2e-46af-bc13-d281d6577606
  4. connection.interface-name: --
  5. connection.type: 802-3-ethernet
  6. connection.autoconnect: yes
  7. ...省略...
  8. ipv4.method: auto
  9. ipv4.dns:
  10. ipv4.dns-search:
  11. ipv4.addresses:
  12. ipv4.routes:
  13. ipv4.ignore-auto-routes: no
  14. ipv4.ignore-auto-dns: no
  15. ipv4.dhcp-client-id: --
  16. ipv4.dhcp-send-hostname: yes
  17. ipv4.dhcp-hostname: --
  18. ...省略...

含义:

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

配置网络

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

2、DHCP自动获取

  1. [root@itcast html]# ncmli connection modify en016777736 \
  2. > connection.autoconnect yes \
  3. > ipv4.method auto
  4. [root@itcast html]# nmcli connection up eno16777736 # 使网络生效
  5. [root@itcast html]# nmcli connection show eno16777736 # 查看配置状态