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

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

----------------------------------------------------------------------------------------------------------------------------------

ubuntu安装好后ifconfig默认只有eth和lo的配置信息:

在ubuntu上面安装KVM后:

KVM里面部署一个虚拟机OS后,又会多出一项信息:

vnet0是KVM给部署的virtual machine OS虚拟的网卡,它通过KVM的虚拟网桥virbr0去连接ubuntu的eth0网卡来联网。

原文地址:https://www.cnblogs.com/kex1n/p/5227232.html