一、/etc/sysconfig/network-scripts/if-cfg文件配置参数说明
DEVICE=物理设备名 IPADDR=IP地址 NETMASK=掩码值 #此处改换为 PREFIX=网络数 也可以 NETWORK=网络地址 BROADCAST=广播地址 GATEWAY=网关地址 ONBOOT=[yes|no](引导时是否激活设备) USERCTL=[yes|no](非root用户是否可以控制该设备) BOOTPROTO=[none|static|bootp|dhcp](引导时不使用协议|静态分配|BOOTP协议|DHCP协议) HWADDR =MAC地址 DNS1=主DNS地址 DNS2=次DNS地址 DNS3=第三DNS地址
参考/usr/share/doc/initscripts-*/sysconfig.txt
二、修改网卡名称
(1)先修改/etc/udev/rules.d/70-persistent-net.rules
[root@CentOS6 ~]#vim /etc/udev/rules.d/70-persistent-net.rules # This file was automatically generated by the /lib/udev/write_net_rules 2 # program, run by the persistent-net-generator.rules rules file. 3 # 4 # You can modify it, as long as you keep each rule on a single 5 # line, and change only the value of the NAME= key. 6 7 # PCI device 0x8086:0x100f (e1000) 8 SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:30 :84:c4", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" #修改NAME值即可
(2)使用命令# vim /etc/sysconfig/network-scripts/ifcfg-eth0,修改网卡的配置文件,如下图修改成与上面自定义的网卡名称一致。
[root@CentOS6 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 1 DEVICE=eth0 #确保DEVICE的值与尚需修改后的值一致 2 ONBOOT=yes 3 BOOTPROTO=static 4 IPADDR=192.168.1.9 5 NETMASK=255.255.255.0
(3)命令#service network restart 重启网络服务让修改生效即可。
[root@CentOS6 ~]# service network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining if ip address 192.168.1.9 is already in use for device eth0... [ OK ]
三、查询系统中的DNS
[root@CentOS6 ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-script search young.com nameserver 8.8.8.8
四、本地解析器
解析器执行正向和逆向查询。
[root@bash ~]# getent hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 127.0.0.1 localhost localhost.localdomain localhost6 localhost6.localdomain6
本地主机名数据库和IP地址的映像
对小型独立网络有用
通常,在使用DNS前检查
注:DNS与hosts文件的先后解析顺序可以由/etc/nsswitch.conf
文件定义
hosts: files dns #先用hosts文件解析,解析不到用dns服务器
五、修改MAC地址
注:#service network restart 重启网络服务让修改生效
六、网卡别名
对虚拟主机有用;将多个IP地址绑定到一个NIC上。
格式:eth0:1 ;eth0:2 ;eth0:3
[root@CentOS6 ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:30:84:C4 inet addr:192.168.1.9 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe30:84c4/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:292854 errors:0 dropped:0 overruns:0 frame:0 TX packets:15988 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:19692302 (18.7 MiB) TX bytes:6278332 (5.9 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:600 errors:0 dropped:0 overruns:0 frame:0 TX packets:600 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:47070 (45.9 KiB) TX bytes:47070 (45.9 KiB) [root@CentOS6 ~]# cdnet [root@CentOS6 network-scripts]# pwd /etc/sysconfig/network-scripts [root@CentOS6 network-scripts]# vim ifcfg-eth0:1 #创建别名文件,填写配置信息 1 DEVICE=eth0:1 2 BOOTPROTO=static 3 IPADDR=192.168.1.11 4 GATEWAY=192.168.1.1 5 PREFIX=24 6 DNS1=8.8.8.8 7 ONBOOT=yes [root@CentOS6 network-scripts]# service network restart #重启网络服务 Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining if ip address 192.168.1.9 is already in use for device eth0... Determining if ip address 192.168.1.11 is already in use for device eth0... [ OK ] [root@CentOS6 network-scripts]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:30:84:C4 inet addr:192.168.1.9 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe30:84c4/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:294011 errors:0 dropped:0 overruns:0 frame:0 TX packets:16447 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:19796414 (18.8 MiB) TX bytes:6362812 (6.0 MiB) eth0:1 Link encap:Ethernet HWaddr 00:0C:29:30:84:C4 inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:600 errors:0 dropped:0 overruns:0 frame:0 TX packets:600 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:47070 (45.9 KiB) TX bytes:47070 (45.9 KiB)
注:设置网卡别名必须使用静态的IP地址;如果安装的Linux系统(CentOS6)是图形界面的, 则需要关闭NetworkManager服务(#chkconfig NetworkManager off
);设置完成后,命令#service network restart
七、网卡模块管理
(1)、查看网卡:
dmesg |grep –i eth ethtool -i eth0
注:dmesg命令被用于检查和控制内核的环形缓冲区。kernel会将开机信息存储在ring buffer中。若是开机时来不及查看信息,可利用dmesg来查看。开机信息保存在/var/log/dmesg文件里。
(2)、卸载网卡驱动:
modprobe -r e1000 rmmod e1000
(3)、装载网卡驱动:
modprobe e1000
八、centos6修改主机名
1.第一步修改/etc/sysconfig/network文件
[root@CentOS ~]#vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=CentOS6 #修改HOSTNAME值
2.第二部修改/etc/hosts文件
[root@CentOS ~]# vim /etc/hosts 1 127.0.0.1 CentOS6 localhost localhost.localdomain localhost4 localhost4.lo caldomain4 2 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
3.上面两步需要重启后生效,不重启执行hostname命令
root@CentOS ~]# hostname CentOS6 [root@CentOS ~]# exit #注销重新登陆生效 [root@CentOS6 ~]# hostname CentOS6 或者 echo 'HOSTNAME' > /proc/sys/kernel/hostname
九、centos7修改网卡采用传统命名方式
1.编辑/etc/default/grub配置文件
在“GRUB_CMDLINE_LINUX”里添加net.ifnames=0 biosdevname=0 保存退出;
或:修改/boot/grub2/grub.cfg
2.为grub2生成其配置文件
grub2-mkconfig -o/boot/grub2/grub.cfg
3.修改网卡配置文件ifcfg-eth0
4.重启系统
转载于:https://blog.51cto.com/yolynn/1896829