網絡屬性配置第三種方式——修改配置文件

網絡屬性配置第三種方式——修改配置文件
IP ,MASK,GW,DNS相關的配置文件:/etc/sysconfig/network-scripts/ifcfg-eth0
路由相關的配置文件:/etc/sysconfig/network-scripts/route-enth0(這個文件默認不存在,需要手動去創建)
(1)/etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost network-scripts]# cat ifcfg-eth0
DEVICE=eth0 (此配置文件應用到的設備)
HWADDR=00:0C:29:2D:9F:69(或MACADDR)
TYPE=Ethernet (接口類型)
UUID=8d1fa98d-630a-4415-8772-a9ad2fe1833d (設備的唯一標識)
ONBOOT=yes (系統引導時激活設備)
NM_CONTROLLED=yes (network manager此網卡是否接受nm控制,建議centos6上禁用)
BOOTPROTO=static (協議dhcp,none)
IPADDR=192.168.176.130
NETMASK=255.255.255.0
GATEWAY=192.168.176.1 (默認網關)
NAME=eth0
DNS1=1.1.1.1
DNS2=8.8.8.8
DNS=114.114.114.114
USERCTL=no(普通用戶是否可控制此設備)
PEERNDS=(如果BOOTPROTO的值為dhcp,是否允許dhcp分配的server分配的dns服務器指向信息直接覆蓋至/etc/resolv.conf文件中)
(2)路由/etc/sysconfig/network-scripts/route-enth0
兩種風格:
!!指明TARGET VIA (經由) GW
!!每三行定義一條路由
ADDRESS1=TARGET
NETMASK1=mask
GATEWAY1=GW
eg:每行一個
[root@localhost network-scripts]# vi route-eth0
172.20.0.0/16 via 192.168.176.1
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.176.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.20.0.0 192.168.176.1 255.255.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.176.1 0.0.0.0 UG 0 0 0 eth0
eg:每三行一個
[root@localhost network-scripts]#vim route-eth0
ADDRESS0=172.20.0.0
NETMASK0=255.255.0.0
GATEWAY0=192.168.176.1
ADDRESS1=172.30.0.0
NETMASK1=255.255.0.0
GATEWAY1=192.168.176.1
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.176.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.30.0.0 192.168.176.1 255.255.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.20.0.0 192.168.176.1 255.255.0.0 UG 0 0 0 eth0
0.0.0.0 192.168.176.1 0.0.0.0 UG 0 0 0 eth0
給網卡配置多地址:
第一個種:ifconfig
ifconfig eth0:0
第二種:ip
ip addr add
第三種:配置文件
ifcfg-eth0:0(指明網卡別名)
DEVICE=eth0:0
[root@localhost network-scripts]# ifconfig eth0:0 192.168.0.22/24 up
[root@localhost network-scripts]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:2D:9F:69
inet addr:192.168.176.130 Bcast:192.168.176.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe2d:9f69/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3018 errors:0 dropped:0 overruns:0 frame:0
TX packets:2728 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:308183 (300.9 KiB) TX bytes:312869 (305.5 KiB)
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:2D:9F:69
inet addr:192.168.0.22 Bcast:192.168.0.255 Mask
注意:網卡別名不能使用dhcp協議引導
網絡接口識別并命名相關的udev配置文件
/etc/udev/rules.d/70-persistent-net.rules
卸載網卡驅動:
#modprobe -r e1000

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:https://www.178linux.com/97666

赞 (1)
单爆手单爆手
上一篇 2018-05-06 22:09
下一篇 2018-05-06 22:23

相关推荐

  • linux基础3

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@localhost ~]# who | cut -d ‘ ‘ -f1 | sort -u root 2、取出最后登录到当前系统的用户的相关信息。 [root@localhost ~]# last -1 | id uid=0(root…

    Linux笔记 2018-07-08
  • 小白加薪升职记第二篇–Linux长征开始

    记录文件管理命令及Linux命令行扩展功能

    Linux笔记 2018-05-19
  • yum配置

    本节简要介绍本地yum配置以及网络yum源的配置

    Linux笔记 2018-04-22
  • 文件管理基础知识

                   文件管理 目录篇 / :根目录 bin    boot    dev    etc    home    root    run     sbin    tmp    usr   var 字符界面颜色的意义: 蓝色=目录、绿色=可执行文件、红色=压缩文件、浅蓝色=链接文件 灰色=其他文件 boot:引导文件的存放目录  bin:…

    Linux笔记 2018-04-08
  • test

       

    Linux笔记 2016-08-01