CentOS 7配置网络

一、配置IP地址

进入到 目录, 修改ifcfg-em1文件:

[root@ccrfox141 ye]# cd  /etc/sysconfig/network-scripts
[root@ccrfox141 network-scripts]# ls
ifcfg-em1  ifcfg-em4   ifcfg-p5p2   ifdown-eth   ifdown-isdn  ifdown-routes  ifdown-TeamPort  ifup-aliases  ifup-ippp  ifup-plip   ifup-ppp     ifup-Team      ifup-wireless      network-functions-ipv6
ifcfg-em2  ifcfg-lo    ifdown       ifdown-ippp  ifdown-post  ifdown-sit     ifdown-tunnel    ifup-bnep     ifup-ipv6  ifup-plusb  ifup-routes  ifup-TeamPort  init.ipv6-global
ifcfg-em3  ifcfg-p5p1  ifdown-bnep  ifdown-ipv6  ifdown-ppp   ifdown-Team    ifup             ifup-eth      ifup-isdn  ifup-post   ifup-sit     ifup-tunnel    network-functions
[root@ccrfox141 network-scripts]# cat ifcfg-em1
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
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="em1"
UUID="087855f4-cfb1-4c45-8d85-60d4ea7f294f"
DEVICE="em1"
ONBOOT="yes"
IPADDR="172.16.0.141"
PREFIX="16"
GATEWAY="172.16.0.254"
DNS1="172.20.1.4"
IPV6_PRIVACY="no"

二、配置DNS

要访问DNS 服务器来进行查询,需要修改设置/etc/resolv.conf文件:

[root@ccrfox141 network-scripts]#  cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 172.20.1.4
nameserver 180.76.76.76

要注意的是直接修改/etc/resolv.conf中的内容只是起临时作用,网络服务重启后系统是根据/etc/sysconfig/network-scripts/ifcfg-em1中的DNS选项来设置nameserver。要想永久有效在文件/etc/sysconfig/network-scripts/ifcfg-em1中添加选项:

DNS2="180.76.76.76"

三、配置路由

[root@ccrfox141 network-scripts]# cat /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.16.0.135 dev em1  

注意最小安装CentOS 7是没有route命令的,需要安装net-tools软件包。


猜你喜欢

转载自blog.csdn.net/yzy1103203312/article/details/80560595