您的位置:首页 > 运维架构 > Linux

linux 网卡配置参数详解

2016-07-14 16:48 615 查看
Linux中不同distribution中配置网络的方法大同小异。以下介绍RHEL6系列,SUSE11, Ubuntu12.04的配置

CentOS,RHEL

/etc/sysconfig/network

NETWORKING=yes # 系统启动时是否启动网络HOSTNAME=zhubinqiangPC # 定义主机名

/etc/udev/rules.d/70-persistent-net.rules 得到网卡的MAC地址

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:58:5f:4b", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

/etc/sysconfig/network-scripts/ifcfg-eth0 配置网卡

配置项有很多个,以下只列出部分重要的。具体可以参考 /usr/share/doc/initscripts-*/sysconfig.txtDEVICE=eth0 # 网卡代号,必须与ifcfg-eth0相对于HWADDR=00:0c:29:58:5f:4b # MAC 地址, 如果只有一个网卡,可以省略TYPE=Ethernet # 网络接口格式 这里是以太网格式UUID=371ea884-5bb7-4e03-9913-127fd7e787ae # nmcli con 可得到 未知什么意思ONBOOT=yes # 开机启动NM_CONTROLLED=yes # controlled by NetworkManagerBOOTPROTO=static # static 和 none 功能相同,表示手动配置, dhcp表示动态获取IPIPADDR=192.168.1.211 # IP 地址NETMASK=255.255.255.0 # 子网掩码GATEWAY=192.168.1.1 # 默认网关,如果有多个网卡配置文件 只须配置一个即可USERCTL=no # 是否允许非root用户控制该设备PEERDNS=yes # yes表示由DHCP来获取DNS, no表示 /etc/resolv.conf 来控制IPV6INIT=no # 是否允许IPV6

修改完配置文件要重启网络

/etc/init.d/network restart

通过ifconfig来配置网络

查看所有网卡ifconfig -a此配置在重启网络后会失效,恢复为ifcfg-eth0为主的配置ifconfig eth0 192.168.0.211 netmask 255.255.255.0ifconfig eth0 192.168.0.211/24修改网卡MAC地址ifconfig eth0 hw ether 00:0C:29:58:5F:4C开启和禁用网卡ifconfig eth0 upifconfig eth0 down

ifup和ifdown来激活与关闭网卡

用ifup来激活 ifcfg-eth0文件要配置正确, 实际是通过/sbin/ifup 来调用相关脚本。注意 一旦用ifconfig 来激活 就不能用ifdown来关闭。 一定要ifconfig才行。因为ifdown会比较当前网络与ifcfg-eth0是否相同,如果不同放弃ifdown的操作ifup eth0 #激活ifdown eth0 #关闭ifconfig eth0 up #激活ifconfig eth0 down #关闭

/etc/resolv.conf 定义DNS服务器

# Generated by NetworkManagerdomain localdomainsearch localdomain # 查找计算机名是 默认属于该域nameserver 192.168.157.2 # DNS 服务器地址, 可以配置多个

通过DHCP获取IP

通过修改ifcfg-ethX的BOOTPROTO=dhcp并重启网络 或者以下方法dhclient eth0/etc/hosts 配置127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

修改hostname

1.修改/etc/sysconfig/network2.修改/etc/hosts

Ubuntu12.04

参考官方文档 https://help.ubuntu.com/12.04/serverguide/network-configuration.html

通过lshw 得到MAC地址

lshw -c network*-networkdescription: Ethernet interfaceproduct: 79c970 [PCnet32 LANCE]vendor: Hynix Semiconductor (Hyundai Electronics)physical id: 1bus info: pci@0000:02:01.0logical name: eth0version: 10serial: 00:0c:29:77:82:a2width: 32 bitsclock: 33MHzcapabilities: bus_master rom ethernet physical logicalconfiguration: broadcast=yes driver=pcnet32 driverversion=1.35 ip=192.168.157.183 latency=64 link=yes maxlatency=255 mingnt=6 multicast=yesresources: irq:19 ioport:2000(size=128) memory:d8400000-d840ffff

/etc/network/interfaces 配置网卡

auto loiface lo inet loopbackauto eth0iface eth0 inet static # 如果是dhcp 则把static改为dhcphwaddress ether 00:13:20:f9:f4:d3 #MACaddress 192.168.1.10 # IP 地址netmask 255.255.255.0 # 子网掩码gateway 192.168.1.1 # 网关

重启网络 生效配置

/etc/init.d/networking restart

/etc/hosts 配置

127.0.0.1 localhost127.0.1.1 zbq-pc192.168.157.136 zbq-pc192.168.157.151 itms-server# The following lines are desirable for IPv6 capable hosts::1 ip6-localhost ip6-loopbackfe00::0 ip6-localnetff00::0 ip6-mcastprefixff02::1 ip6-allnodesff02::2 ip6-allrouters

hostname 修改 /etc/hostname

SUSE11

cat /etc/udev/rules.d/70-persistent-net.rules 查看MAC

修改 /etc/sysconfig/network/ifcfg-eth0

BOOTPROTO='dhcp'BROADCAST=''ETHTOOL_OPTIONS=''IPADDR=''MTU=''NAME='82545EM Gigabit Ethernet Controller (Copper)'NETMASK=''NETWORK=''REMOTE_IPADDR=''STARTMODE='auto'USERCONTROL='no'

重启网络

/etc/init.d/network restart
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 配置详解 网卡