Centos7设定网络

新安装的centos7,网络默认是不启动的,需要人为的手工修改配置文件,在这里把这个过程简要的记录一下。

  • 设定ip地址与mac地址自定义
[root@web ~]# cd /etc/sysconfig/network-scripts
[root@web network-scripts]# ls
ifcfg-ens160  ifdown-ippp  ifdown-routes    ifup          ifup-ipv6   ifup-ppp       ifup-tunnel
ifcfg-lo      ifdown-ipv6  ifdown-sit       ifup-aliases  ifup-isdn   ifup-routes    ifup-wireless
ifdown        ifdown-isdn  ifdown-Team      ifup-bnep     ifup-plip   ifup-sit       init.ipv6-global
ifdown-bnep   ifdown-post  ifdown-TeamPort  ifup-eth      ifup-plusb  ifup-Team      network-functions
ifdown-eth    ifdown-ppp   ifdown-tunnel    ifup-ippp     ifup-post   ifup-TeamPort  network-functions-ipv6
[root@web network-scripts]# more ifcfg-ens160 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
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=ens160
UUID=028745b4-7fff-408f-ad04-e488da3c100a
DEVICE=ens160
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.17.109.3
PREFIX=24
GATEWAY=172.17.109.1
DNS1=172.17.5.1
MACADDR=18:a9:05:4e:ad:02  
IPV6_PRIVACY=no

[root@web network-scripts]# systemctl restart network
  •  配置静态路由
[root@web network-scripts]# vi route-ens160
[root@web network-scripts]# cat route-ens160 
172.0.0.0/8 via 172.17.109.254 dev ens160
[root@web network-scripts]# systemctl restart network
[root@web network-scripts]# ip route
default via 172.17.109.1 dev ens160 proto static metric 100 
172.0.0.0/8 via 172.17.109.254 dev ens160 proto static metric 100 
172.17.109.0/24 dev ens160 proto kernel scope link src 172.17.109.3 metric 100
  •  安装wget及设定阿里云yum镜象源
[root@web yum.repos.d]# yum install wget
[root@web yum.repos.d]# wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-10-19 03:57:56--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 14.215.83.248, 113.96.109.96, 183.2.199.241, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|14.215.83.248|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “CentOS-Base.repo”

100%[==========================================================================>] 2,523       --.-K/s 用时 0s      

2019-10-19 03:57:56 (147 MB/s) - 已保存 “CentOS-Base.repo” [2523/2523])

[root@web yum.repos.d]# yum makecache
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                         | 3.6 kB  00:00:00     
extras                                                                                       | 2.9 kB  00:00:00     
updates                                                                                      | 2.9 kB  00:00:00     
元数据缓存已建立
[root@web yum.repos.d]# yum update
  •  安装 net-tools工具包后,可以使用netstat  ifconfig 等网络命令
[root@web yum.repos.d]# yum install net-tools
  • 启用firewalld防火墙
    [root@web yum.repos.d]# systemctl enable firewalld
    [root@web yum.repos.d]# systemctl restart  firewalld
    [root@web yum.repos.d]# firewall-cmd --list-all
    public (active)
      target: default
      icmp-block-inversion: no
      interfaces: ens160
      sources: 
      services: dhcpv6-client ssh
      ports: 
      protocols: 
      masquerade: no
      forward-ports: 
      source-ports: 
      icmp-blocks: 
      rich rules: 

     

posted on 2019-10-18 19:37  湖东  阅读(2670)  评论(0编辑  收藏  举报