Linux 设置静态IP以及DNS

在虚拟机中安装Linux无法DHCP获取地址,搜了点资料设置成功了,记下来好找资料。

设置静态ip

vi /etc/network/interfaces
# The primary network interface  
auto eth0  #表示让网卡开机自动挂载eth0
iface eth0 inet static  
address 192.168.2.1  
gateway 192.168.2.254  
netmask 255.255.255.0

/etc/init.d/networking restart
or
service networking restart
```
```
# Centos**
vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0C:29:1D:86:BD
NM_CONTROLLED=yes
ONBOOT=yes
TYPE=Ethernet
UUID=da0d1da0-568a-45cf-a93f-66a30a4870e7
IPADDR=192.168.1.12
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
IPV6INIT=no
USERCTL=no

设置DNS

vi  /etc/resolvconf/resolv.conf.d/base
#添加
nameserver 8.8.8.8
nameserver 8.8.4.4

resolvconf -u
```
```
# Centos
vi /etc/resolv.conf

nameserver 168.95.1.1
nameserver 8.8.8.8
           

1 comment

Comments feed for this article

  1. Linux’s avatar

    Hi Xu,

    for CentOS 7 or later.
    we can use “NetworkManager” process to manage the network.
    only one command for change network. quickly

    #nmcli connection modify ens192 ipv4.addresses 1.1.1.1/24 ipv4.gateway 1.1.1.254 ipv4.dns 8.8.8.8 ipv4.method static
    #nmcli connection up ens192

    Reply

Reply

Your email address will not be published. Required fields are marked *