ubuntu/centos网络配置

时间:2022-07-13 18:20:44
UBUNTU网络配置

配置临时的Ip

  ifconfig eth0 192.168.3.136/

其中24指的网络掩码24位。

  vim /etc/network/interfaces 添加下面内容

  auto eth0                   #开机自动连接

  iface eth0 inet static  #静态IP

  address 192.168.1.112

  netmask 255.255.255.0

  gateway 192.168.1.1

如果是dhcp,添加

  auto eth0

  iface eth0 inet dhcp

DNS配置:

vim /etc/resolv.conf

      nameserver 202.96.128.166

  nameserver 202.96.134.133

  nameserver 8.8.8.8

在resolv.conf文件中添加一些DNS服务器(例如电信)的IP地址即可。

网络重启:

  sudo /etc/init.d/networking restart

关闭网卡:

  sudo ifconfig eth0 down

打开网卡

  sudo ifconfig eth0 up

centos网络配置

在networ-scripts目录下,不同的网卡对应不同的配置文件。

sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0

  DEVICE=eth0

  IPADDR=192.168.3.136

  NETMASK=255.255.255.0

  GATEWAY=192.168.3.1

  HWADDR=:0C::C1::F6

  ONBOOT=yes      #开机启动

  NM_CONTROLLED=yes

  BOOTPROTO=static

DNS配置

vim /etc/resolv.conf

  nameserver 202.96.128.166

  nameserver 202.96.134.133

服务重启:

      sudo service network restart

启动

  sudo service network start

关闭

  sudo service network stop