ifcfg, ip, ss,配置文件 (Blog 7)

Linux主机接入网络:
IP/MASK
GATEWAY
DNS

ifcfg家族:众多发行版均支持的最古老的linux主机上管理网络的命令;
ifconfig:IP和接口
route:路由表
netstat:统计状态
hostname:主机名
system-config-network:命令修改配置,不会立即生效;

ip家族:
ip:IP,接口,路由表
ss:统计状态数据

CentOS 7:
nmcli:修改配置文件:IP,接口,路由表
nmtui: 修改配置文件:

注意:TCP/IP协议栈在内核空间中实现,用于配置TCP/IP协议相关属性的命令,会直接修改内核空间的内核内存中的数据;会立即生效,重启系统后失效;

配置文件:REHL系主机独有的配置;
/etc/sysconfig/network-scritps/ifcfg-IFACE
/etc/resolv.conf
/etc/hosts

网卡命名格式:
o<> 集成设备的设备索引号
s<slot> 扩展槽索引号
p<bus>s<slot> 总线及槽索引号
x<MAC> MAC地址命名
eth# 传统
ppp# PPP网络命名

ifcfg家族

ifconfig命令:
显示接口:ifconfig [-a] [interface]
显示激活:ifconfig
显示所有:ifconfig -a
显示指定接口:ifconfig IFACE
显示数据:
MAC地址:C6: HWaddr 00:0C:29:CC:57:50 C7: ether 00:0c:29:63:86:f6
当前接口属性状态:UP BROADCAST RUNNING MULTICAST PROMISC
mtu 1500 inet 192.168.3.119 netmask 255.255.255.0 broadcast 192.168.3.255
txqueuelen 1000 (Ethernet) 传输队列
RX packets:111 errors:0 dropped:0 overruns:0 frame:0 <–接收
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0 <–发送
collisions:0 冲突的
RX bytes:10993 (10.7 KiB):总接收 TX bytes:828 (828.0 b):总传输

配置接口:ifconfig interface options | address …
接口配置地址:ifconfig IFACE address
address表示方式:192.168.1.2/24
PRIFIX:前缀是一个IP地址,后面有一个斜杠和前缀长度。
例如:
# ifconfig eth1 192.168.1.2/24

配置接口属性:ifconfig IFACE { up | donw | [-]promisc | mtu N }
Maximum Transfer Unit (MTU) IP报文大小;默认1500

添加ipv6地址:add addr/prefixlen
移除ipv6地址:del addr/prefixlen

例如:
# ifconfig eth1 up|down
# ifconfig eth1 promisc
# ifconfig eth1 -promisc

注意:
(1) 单接口多地址:IFACE可以是别名:例如:接口名eth0 –> 别名:eth0:0
(2) 如果eth0关闭,其别名也会被关闭;

route命令:
查看内核中的路由表:route [-n]
-n:默认将IP反解为主机名,-n表示不反解主机名;
添加或移除路由条目:route add|del -net|-host target gw Gw [[dev] IFACE]
target表示:
添加主机路由时:IP或IP/32
添加网络路由时:PREFIX

添加:
~]# route add -host 10.0.0.1 gw 192.168.3.1 dev eno16777736
~]# route add -net 10.0.0.0/8 gw 192.168.3.4 dev eno16777736

注意:添加时,先查看网卡所在网络;其GW必须与接口处于同一个网络;

netstat: Print network connections, routing tables, interface statistics(接口统计信息), masquerade connections(隐藏连接),
and multicast memberships(多播成员)

routing tables: netstat -rn
-r 内核路由表
-n 不反解IP–>FQDN

interface statistics:netstat [–tcp|-t] [–udp|-u] [–udplite|-U] [–sctp|-S] [–raw|-w] [–listening|-l] [–all|-a] [–numeric|-n] [–numeric-hosts] [–numeric-ports] [–extend|-e[–extend|-e]] [–program|-p]
协议: tcp, udp, sctp, udplite, raw
-t: TCP,连接均有状态;均在有限状态机状态范围内转换[FSM Finate State Machine];
-u: UDP,连接无状态;只有ESTABLISHED;
-w: raw socket: 裸套接字
-l: listen状态
-a: 所有状态
-n: 以数字格式显示IP和PORT;
-e: 扩展格式;
-p:显示相关的进程及PID;

Proto 协议
Recv-Q 接收队列中等待的个数;
Send-Q 发送队列中等待的个数;
Local Address 本地地址
Foreign Address 远程主机地址;
State 状态
User 进程文件的属主
Inode 进程文件的inode
PID/Program name 进程PID和进程名

常用组合:tan, tnl, tunlp

注意:
tcp有状态:
LISTEN[守株待兔], ESTABLISHED[热恋], FIN_WAIT_1[分手], FIN_WAIT_2[确认], SYN_SENT[死缠烂打没必要,离了谁都可以活], SYN_RECV, CLOSED
udp无状态: 通信和监听

interface statistics:netstat {–interfaces|-I|-i} [–all|-a] [–extend|-e] [–verbose|-v] [–program|-p] [–numeric|-n]
显示所有接口状态:netstat -i
显示指定接口状态:netstat -I<IFACE>

hostname命令:
显示当前主机名:hostname
设定主机名:hostname [HOSTNAME]
注意:当前系统重启终端生效,重启系统后无效;如果重启有效,则需要定义在配置文件中:/etc/sysconfig/network

hostnamectl命令:C7特有的命令;会修改配置文件;
显示当前主机名信息:hostnamectl status
设定主机名:hostnamectl set-hostname HOSTNAME
–pretty 好看的主机名
–static 静态的主机名
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host

ifup命令: ifdown命令:
启动或停止接口: ifup | ifdown IFACE

ip家族

ip命令: 设定路由, 策略路由, 遂道;

获取帮助: # ip COMMAND help
link: 接口属性
netns: name space “名称空间”管理
addr: 接口地址
route: 路由设定

#接口属性管理:
ip link SUB_COMMAND
show [IFACE] 显示接口属性;显示二层设备的属性;
set IFACE <OPTIONS>
up,down 启用或禁用接口;
arp {on|off} arp功能
multicast {on|off} 多播功能
promisc {on|off} 混杂模式
mtu MTU 设定MTU大小
name NAME 接口名称设定,注意需要禁用接口后,方可设定;
peer ADDRESS 对等传输地址;
netns PID 将接口移入到指定的名称空间;ns(name space)

显示接口属性: ~]# ip link show eno16777736
<BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
MULTICAST:多播;
UP: 启用;
mtu: MTU值;
qdisc:队列;
pfifo_fast: 类型;
qlen: 队列长度

启用或禁用接口:注意显示的UP状态;
~]# ip link show
3: eno33554976: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—禁用
~]# ip link set eno33554976 down
~]# ip link show
3: eno33554976: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—启用
~]# ip link set eno33554976 up
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff

多播功能启用或禁用:注意显示的MULTICAST状态;
~]# ip link show
3: eno33554976: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—禁用
~]# ip link set eno33554976 multicast off
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—启用
~]# ip link set eno33554976 multicast on
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff

arp功能: 注意NOARP
—禁用
~]# ip link set eno33554976 arp off
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—启用
~]# ip link set eno33554976 arp on
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff

混杂模式: 破解无线密码必备;注意:PROMISC是否出现
—启用
~]# ip link set eno33554976 promisc on
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,NOARP,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—禁用
~]# ip link set eno33554976 promisc off
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff

mtu大小:mtu
—默认1500
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—1600
~]# ip link set eno33554976 mtu 1600
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1600 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—1500
~]# ip link set eno33554976 mtu 1500
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff

修改接口名称:
—禁用接口
~]# ip link set eno33554976 down
~]# ip link show eno33554976
3: eno33554976: <BROADCAST,MULTICAST,NOARP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—修改名称
~]# ip link set eno33554976 name eth0
~]# ip link show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff

#name space “名称空间”管理
ip netns SUB_COMMAND
list 列出所有netns;
add NAME 添加Netns;
del NAME 删除netns;
exec NAME COMMAND 在netns中执行命令;

列出所有netns:
~]# ip netns list

添加netns:
—添加mynet
~]# ip netns add mynet
—列出
~]# ip netns list
mynet

删除netns:
—删除mynet
~]# ip netns del mynet
—列出
~]# ip netns list

在netns中列出执行命令:
—添加mynet
~]# ip netns add mynet
—列出
~]# ip netns list
mynet
—将接口加入netns: 隐藏接口
~]# ip link set eth0 netns mynet
~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:f6 brd ff:ff:ff:ff:ff:ff
—列出netns中的接口
~]# ip netns exec mynet ip link show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
—移除netns:自动归还接口
~]# ip netns del mynet
~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:f6 brd ff:ff:ff:ff:ff:ff
3: eno33554976: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff

#接口地址管理:
ip addr SUB_COMMAND
add|del IFADDR [OPTIONS] dev IFACE 添加/删除地址;
show|flush [OPTIONS] [IFACE] 查看/清空地址;

—-添加或删除地址:
ip addr add|del IFADDR [OPTIONS] dev IFACE
label NAME 接口别名;可以在Ifconfig中查看;
broadcast ADDRESS 广播地址,会根据ip和mask自动计算;
scope SCOPE_VALUE 配置的IP的作用域:
global – 全局可用;
link – 接口可用;
host – 本机内部可用;
注意:
IFADDR是IP的前缀及其长度组成;例如:192.168.3.1/24
在同一个网络内有一个primary地址和多个secondary地址;

—-查看或清空地址:
ip addr show|flush [OPTIONS] [IFACE]
[primary]|[secondary] 显示主地址;

查看eth0当前地址:
~]# ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
inet 192.168.128.128/24 brd 192.168.128.255 scope global dynamic eth0
valid_lft 1791sec preferred_lft 1791sec
inet6 fe80::20c:29ff:fe63:8600/64 scope link
valid_lft forever preferred_lft forever
清空eth0当前地址:
~]# ip addr flush eth0
~]# ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
添加地址:
~]# ip addr add 10.100.100.1/24 dev eth0
~]# ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
inet 10.100.100.1/24 scope global eth0
valid_lft forever preferred_lft forever
删除地址:
~]# ip addr del 10.100.100.1/24 dev eth0
~]# ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff

添加多个地址:
~]# ip addr add 10.100.100.1/24 dev eth0
~]# ip addr add 10.100.100.2/24 dev eth0
~]# ip addr add 10.100.100.3/24 dev eth0
~]# ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
inet 10.100.100.1/24 scope global eth0
valid_lft forever preferred_lft forever
inet 10.100.100.2/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 10.100.100.3/24 scope global secondary eth0
valid_lft forever preferred_lft forever
注意:只有第一个是global, 其它都是secondary

添加别名地址:
~]# ip addr add 10.100.101.2/24 label eth0:0 dev eth0
~]# ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
inet 10.100.100.1/24 scope global eth0
valid_lft forever preferred_lft forever
inet 10.100.101.2/24 scope global eth0:0
valid_lft forever preferred_lft forever
inet 10.100.100.2/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 10.100.100.3/24 scope global secondary eth0
valid_lft forever preferred_lft forever
注意:添加别名后ifconfig只能查看别名;其它地址均不能查看;
~]# ifconfig
eth0: flags=4291<UP,BROADCAST,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.100.100.1 netmask 255.255.255.0 broadcast 0.0.0.0
ether 00:0c:29:63:86:00 txqueuelen 1000 (Ethernet)
RX packets 679 bytes 44011 (42.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 64 bytes 7565 (7.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

eth0:0: flags=4291<UP,BROADCAST,RUNNING,NOARP,MULTICAST> mtu 1500
inet 10.100.101.2 netmask 255.255.255.0 broadcast 0.0.0.0
ether 00:0c:29:63:86:00 txqueuelen 1000 (Ethernet)

#路由设定

添加/删除: ip route add PRIFIX via ADDRESS dev NAME [src ADDRESS]
查看/清空: ip route show/flush [OPTION] dev NAME
PRIFIX: 前缀是一个IP地址,后面有一个斜杠和前缀长度。
src ADDRESS 配置多个地址时,使用哪个地址作为源地址;
NAME: 通过哪个接口出去;

查看路由表:
~]# ip route show
default via 192.168.3.254 dev eno16777736 proto static metric 100
10.100.100.0/24 dev eth0 proto kernel scope link src 10.100.100.1
10.100.101.0/24 dev eth0 proto kernel scope link src 10.100.101.2
192.168.3.0/24 dev eno16777736 proto kernel scope link src 192.168.3.119 metric 100

查看接口地址:
~]# ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:63:86:00 brd ff:ff:ff:ff:ff:ff
inet 10.100.100.1/24 scope global eth0
valid_lft forever preferred_lft forever
inet 10.100.101.2/24 scope global eth0:0
valid_lft forever preferred_lft forever
inet 10.100.100.2/24 scope global secondary eth0
valid_lft forever preferred_lft forever
inet 10.100.100.3/24 scope global secondary eth0
valid_lft forever preferred_lft forever

添加主机路由,到172.16.0.2经过eth0:0接口至10.100.101.100网关出去;设定源地址为10.100.101.2;
~]# ip route add 172.16.0.2 via 10.100.101.100 dev eth0:0 src 10.100.101.2

添加网络路由,到172.16.0.0/16经过eth0接口至10.100.100.100网关出去;设定源地址为10.100.100.3;
~]# ip route add 172.16.0.0/16 via 10.100.100.100 dev eth0 src 10.100.100.3

查看路由表:
~]# ip route show
172.16.0.0/16 via 10.100.100.100 dev eth0 src 10.100.100.3
172.16.0.2 via 10.100.101.100 dev eth0 src 10.100.101.2

添加默认路由:
~]# ip route add default via 10.100.100.2 dev eth0
~]# ip route add default via 10.100.101.2 dev eth0:0

清空路由表:
via PRIFIX
~]# ip route show via 10.100.100.222
172.16.100.12 dev eth0
172.16.100.13 dev eth0 src 10.100.100.1
~]# ip route flush via 10.100.100.222
~]# ip route show via 10.100.100.222

src PRIFIX
[root@www ~]# ip route show src 10.100.101.2
10.100.101.0/24 dev eth0 proto kernel scope link
172.16.0.2 via 10.100.101.100 dev eth0
~]# ip route flush src 10.100.101.2
~]# ip route show src 10.100.101.2

dev IFACE
[root@www ~]# ip route show dev eth0
default via 192.168.128.2 proto static metric 101
10.100.100.0/24 proto kernel scope link src 10.100.100.1
172.16.0.0/16 via 10.100.100.100 src 10.100.100.3
192.168.128.0/24 proto kernel scope link src 192.168.128.128 metric 100
~]# ip route flush dev eth0
~]# ip route show dev eth0
..

删除路由:
[root@www ~]# ip route show
default via 192.168.3.254 dev eno16777736 proto static metric 100
172.16.100.100 via 192.168.3.222 dev eno16777736
192.168.3.0/24 dev eno16777736 proto kernel scope link src 192.168.3.119 metric 100
[root@www ~]# ip route del 172.16.100.100 dev eno16777736
[root@www ~]# ip route show
default via 192.168.3.254 dev eno16777736 proto static metric 100
192.168.3.0/24 dev eno16777736 proto kernel scope link src 192.168.3.119 metric 100

ss命令:
ss [options] [ FILTER ]
[options]
-t: tcp协议相关的连接
-u: udp协议相关的连接
-w: raw scket 相关的连接;
-l: 监听状态的连接;
-a: 所有状态 的连接
-n: 数字格式
-p: 相关程序及PID号
-e: 扩展的信息;

-m: 显示内存用量;
-o: 显示计时器信息;

[ FILTER ]
FILTER := [ state TCP-STATE ] [ EXPRESSION ]

注意: udp无状态的连接;仅有通信和监听;

显示tcp/udp相关的正在通信连接:
# ss -tn
# ss -un
显示tcp/udp相关的监听的连接:
# ss -tnl
# ss -unl
显示tcp所有状态的连接
# ss -tan
显示tcp/udp监听的连接:
# ss -tunlp

过滤状态: ~]# ss -tan state ESTABLISHED
过滤端口: ~]# ss -tan ‘( dport = :22 or sport = :22 )’
注意: 冒号的位置

#配置文件:

命令配置”IP”和”路由”在系统启动后会失效,要想永久有效需要修改配置文件;
/etc/sysconfig/network-scripts/
ifcfg-IFACE
route-IFACE

ifcfg-IFACE 配置文件参数:
NETBOOT 是否支持网络引导;
UUID 此设备的唯一标识;
TYPE 接口类型; Ethernet, Bridge;
DOMAIN 自己所处的域名后缀;DNS搜索域;
DEFROUTE 是否为默认路由使用的接口;
HWADDR MAC地址

DEVICE 此配置文件对应的设备的名称;必须与IFACE保持一致;
ONBOOT 在系统引导过程中,是否激活此接口;
BOOTPROTO 激活此接口时,使用什么协议来配置接口属性; dhcp, bootp, statics, none
IPADDR IP地址;
NETMASK 子网掩码;CentOS 7支持以长度方式指明子网掩码;
GATEWAY 默认网关;
DNS1 第一DNS服务器指向;
DNS2 备用DNS服务器指向,如果主DNS不能连接时才会使用备用DNS;
USERCTL 是否允许普通用户控制此设备;
PEERDNS 如果BOOTPROTO的值为’dhcp’,是否允许dhcp server分配的dns服务器指向覆盖本地手动指定的DNS服务器指向;默认为允许;
IPV6_INIT 是否初始化IPv6; 不用不需要初始化;
NM_CONTROLLED 是否使用NetworkManager服务来控制接口;

route-IFACE 配置文件参数:
(1) 每行一个路由条目;
TARGET via GW
(2) 每三行一个路由条目;
ADDRESS#=TARGET
NETMASK#=MASK
GATEWAY#=NEXTHOP

注意:配置时只能有一种风格;

配置后不会立即生效,需要重启服务生效:
C6: service network restart
C7: systemctl restart network.service

例如:

配置IP
NAME=’eth0′
DEVICE=’eth0′
TYPE=Enthernet
DEFROUTE=no
HWADDR=’00:0c:29:63:86:00′
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.16.100.9
NETMASK=255.255.0.0
GATEWAY=172.16.0.1
DNS1=172.16.0.1
DNS2=172.16.0.2
DNS3=172.16.0.3
USERCTL=no
NM_CONTROLLED=no
IPV6_INIT=no
PEERDNS=no

配置路由表
(1) 每行一个路由条目;
172.31.100.100 via 172.16.100.7
172.30.0.0/16 via 172.16.0.1
[root@www network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.30.0.0 172.16.0.1 255.255.0.0 UG 0 0 0 eth0
172.31.100.100 172.16.100.7 255.255.255.255 UGH 0 0 0 eth0

(2) 每三行一个路由条目;
[root@www network-scripts]# rm route-eth0
rm:是否删除普通文件 “route-eth0″?y
[root@www network-scripts]# cat route-eth0
ADDRESS0=192.168.0.253
NETMASK0=255.255.255.255
GATEWAY0=172.16.254.254

ADDRESS1=192.168.1.0
NETMASK1=255.255.255.0
GATEWAY1=172.16.0.1

[root@www network-scripts]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.0.253 172.16.254.254 255.255.255.255 UGH 0 0 0 eth0
192.168.1.0 172.16.0.1 255.255.255.0 UG 0 0 0 eth0

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

(0)
逆神阳逆神阳
上一篇 2017-11-27
下一篇 2017-11-27

相关推荐

  • 强大的查找工具之find命令

    一、Linux中的文件查找工具     在文件系统上常常需要根据文件的各种属性去查找符合条件的文件,此前讲到的grep、egrep属于文本过滤、文本搜索工具;而文本查找工具有两个,local和find 二、Linux中的查找工具简介 locate 命令 find 命令 简介:locate属于非实时查找,依赖于事先构建的索引;索引的创建是在…

    Linux干货 2016-08-16
  • 第二周作业新

    一、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。 pwd :显示当前所在路径   cd :切换目录   cd – :在上次目录与当前目录之间切换。   cd ~ :切换回自己的家目录   cd . :当前目录      cd .. :切换到…

    2017-02-18
  • btrfs管理和应用

    一、btrfs概念        在btrfs中存在三种类型的数据,data, metadata和system。它们表示:        DATA           数据块。       &nbsp…

    系统运维 2016-04-12
  • 马哥教育网络班21期+第三周博客作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 方法1: [root@zabbix ~]# who |awk '{print $1}'|sort -n|uniq monitor root 方法2: [root@zabbix ~]#…

    Linux干货 2016-07-22
  • 计算机基础第一部分

    ** 第一课:计算机基础知识** 第一章计算机的组成 计算机是由硬件(Hardwaer)和软件(Software)来组成两大类,他是一台可以自由传输数据, 储存数据,娱乐,工作等等的智能设备。 第一节计算机硬件 主板架构图 内存====用来存储临时数据,弱点喜欢松动一般电脑黑屏都是他松动了,导致电脑不能机 基本上%80以上的电脑不能开机都是他出了问题,服务器…

    Linux干货 2017-05-19
  • 很认真的第十三周作业哦

    1、建立samba共享,共享目录为/data,要求:(描述完整的过程) mkdir /data #建立共享目录 1)共享名为shared,工作组为magedu vim /etc/samba/smb.conf 修改 workgroup = MYGROUP 为 workgroup = magedu 修改 passdb backend = tdbsam 为 pas…

    Linux干货 2017-03-27