centos 7 网络配置( 网关、dns、ip地址配置)

centos 7 网络配置( 网关、dns、ip地址配置)插图

1.配置DNS (可忽略)
vim   /etc/resolv.conf
nameserver 192.168.0.1
nameserver 8.8.8.8
nameserver 8.8.4.4

2.配置网关
route add default gw 192.168.1.1 dev eno*
这样就把网关修改为192.168.1.1了,这种修改只是临时的,当你重新启动系统或网卡之后,还是会变回原来的网关。要想永久性修改,就要修改/etc/sysconfig/network 这个文件,这个文件的主要内容如下(你的文件中没有的项,你可以手动添加):

vim  /etc/sysconfig/network
NETWORKING=yes #表示系统是否使用网络,一般设置为yes。如果设为no,则不能使用网络。

HOSTNAME=centos #设置本机的主机名,这里设置的主机名要和/etc/hosts中设置的主机名对应

GATEWAY=192.168.1.1 #设置本机连接的网关的IP地址。

3.配置ip地址
vim  /etc/sysconfig/network-scripts/ifcfg-eno*
HWADDR=00:0C:29:8D:24:73
 TYPE=Ethernet
 BOOTPROTO=static  #启用静态IP地址
 DEFROUTE=yes
 PEERDNS=yes
 PEERROUTES=yes
 IPV4_FAILURE_FATAL=no
 IPV6INIT=yes
 IPV6_AUTOCONF=yes
 IPV6_DEFROUTE=yes
 IPV6_PEERDNS=yes
 IPV6_PEERROUTES=yes
 IPV6_FAILURE_FATAL=no
 NAME=eno16777736
 UUID=ae0965e7-22b9-45aa-8ec9-3f0a20a85d11
 ONBOOT=yes  #开启自动启用网络连接
 IPADDR0=192.168.21.128  #设置IP地址
 PREFIXO0=24  #设置子网掩码
 GATEWAY0=192.168.21.2  #设置网关
 DNS1=8.8.8.8  #设置主DNS
 DNS2=8.8.4.4  #设置备DNS
 :wq!  #保存退出

4.设置主机名为www
vim /etc/hostname #编辑配置文件

www   #修改localhost.localdomain为www

vim /etc/hosts #编辑配置文件

127.0.0.1   localhost  www   #修改localhost.localdomain为www

5.重新启动服务
ip link set eth0 upi          # 开启网卡
ip link set eth0 down         # 关闭网卡

service network restart

标签

发表评论

评论列表(12)

    • qhj0928

      2020.10.30 12:10

      I cannot understand

  • I am genuinely grateful to the holder of this website
    who has shared this fantastic post at at this time.

    回复
  • School Design Images English Literature Aqa Gcse Past Papers

    Look at my web site; ebook (trumponcoronavirus.blogspot.com)

    回复
  • Ann

    2020.7.20 04:07

    Thanks for your personal marvelous posting! I truly enjoyed reading it, you could be
    a great author. I will make certain to bookmark your blog and will come back down the road.

    I want to encourage you to continue your great job, have a nice morning!

    回复
  • Quickbooks premier

    2020.7.5 01:07

    Good day! I could have sworn I’ve visited this blog before but after going through some of the articles I realized it’s new to me. Anyhow, I’m certainly pleased I discovered it and I’ll be bookmarking it and checking back often!

    回复
  • g

    2020.6.17 16:06

    You actually make it appear really easy along with your
    presentation but I to find this topic to be actually something which I feel I’d by no means understand.

    It kind of feels too complicated and extremely large for me.
    I am taking a look ahead in your next publish, I will
    try to get the hold of it!

    回复
  • g

    2020.6.17 03:06

    I am sure this piece of writing has touched all the internet viewers, its really really good post on building up new webpage.

    回复
  • g

    2020.6.16 09:06

    Hi, Neat post. There is an issue along with your website in web explorer,
    may test this? IE still is the marketplace leader and a huge section of folks will leave out your great writing
    because of this problem.

    回复
  • g

    2020.6.15 22:06

    I am curious to find out what blog system you have been working with?
    I’m having some minor security issues with my latest site and I would
    like to find something more secure. Do you have any recommendations?

    回复
  • Howdy are using WordPress for your blog platform? I’m new to the
    blog world but I’m trying to get started and set up
    my own. Do you require any coding knowledge to make
    your own blog? Any help would be really appreciated!

    回复
  • Fleck 5600SXT System

    2020.4.4 05:04

    The other day, while I was at work, my sister
    stole my iPad and tested to see if it can survive
    a 40 foot drop, just so she can be a youtube sensation. My apple ipad is now destroyed and she has 83 views.
    I know this is completely off topic but I had to share it with
    someone!

    回复