linux之网络配置相关

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux之网络配置相关相关的知识,希望对你有一定的参考价值。

ubuntu的网络配置文件在 /etc/network/intrfaces;

suse的网络配置在          /etc/sysconfig/network/下面,每个网卡一个配置文件。

 

intrfaces如下内容表示使用DHCP分配IP:
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

 

Dynamic Host Configuration Protocol (DHCP) is a client/server protocol that automatically provides an Internet Protocol (IP) host with its IP address and other related configuration information such as the subnet mask and default gateway.

 

修改为如下表示配置静态IP地址:
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
#iface eth0 inet dhcp

iface eth0 inet static
address 192.168.80.129
netmask 255.255.255.0
gateway 192.168.80.2

注意:只需要设置address(IP地址)、netmask(子网掩码)、gateway(网关)这三项就OK,network和broadcast这两项参数是可以不写的。

 

设置DNS服务器

都在/etc/resolv.conf这个文件内配置。

内容:

nameserver 192.168.80.2
nameserver 8.8.8.8

保存退出。

注意:重启Ubuntu后发现又不能上网了,问题出在/etc/resolv.conf。重启后,此文件配置的dns又被自动修改为默认值。所以需要永久性修改DNS。方法如下:

# vim /etc/resolvconf/resolv.conf.d/base
nameserver 192.168.80.2
nameserver 8.8.8.8

3、重启networking服务使其生效:

# /etc/init.d/networking restart

这样网络配置就永久生效。

 

以上是关于linux之网络配置相关的主要内容,如果未能解决你的问题,请参考以下文章

Linux网络服务—DHCP

Linux服务器搭建之DHCP服务器

Linux网络服务之DHCP服务原理与自动获取实验

LINUX网络服务01:DHCP

玩转 OpenStack(八.1)Linux Bridge 实现 Neutron 网络之Local、Flat、VLAN、DHCP

Linux中不得不了解的基础之DHCP!!!