0%

Linux-路由添加

网络配置

DNS服务器配置

/etc/resolv.conf ##### 格式

1
2
nameserver DNS_SERVER_IP1
nameserver DNS_SERVER_IP2

RHEL

网络配置文件

/etc/sysconfig/network

主机名配置

/etc/sysconfig/network

网络接口配置文件

/etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME

格式
1
2
3
4
5
6
7
8
9
DEVICE=: 关联的设备名称,要与文件名的后半部“INTERFACE_NAME”保持一致; 
BOOTPROTO={static|none|dhcp|bootp}: 引导协议;要使用静态地址,使用static或none;dhcp表示使用DHCP服务器获取地址;
IPADDR=: IP地址
NETMASK=:子网掩码
GATEWAY=:设定默认网关;
ONBOOT=:开机时是否自动激活此网络接口;
HWADDR=: 硬件地址,要与硬件中的地址保持一致;可省;
USERCTL={yes|no}: 是否允许普通用户控制此接口;
PEERDNS={yes|no}: 是否在BOOTPROTO为dhcp时接受由DHCP服务器指定的DNS地址;

路由配置文件

/etc/sysconfig/network-scripts/route-INTERFACE_NAME

格式
1
2
3
4
5
6
#1
DEST via NEXTHOP
#2
ADDRESS0=ip
NETMASK0=netmask
GATEWAY0=gateway

Debian

网络配置文件

网卡的所有配置都在/etc/network/interfaces

主机名配置

/etc/hostname /etc/hosts #### 路由配置

多网卡静态路由配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# The primary network interface
auto eth0 #网卡开机启动
iface eth0 inet static #定义为静态 IP
mtu 1492 #定义 MTU
address 192.168.100.113 #定义 IP 地址
netmask 255.255.255.0 #定义子网掩码
dns-nameservers 192.168.100.253 #定义 DNS
up route add -net 192.168.0.0/16 gateway 192.168.100.1 dev eth0 #eth0 连接增加静态路由
down route del -net 192.168.0.0/16 gateway 192.168.100.1 dev eth0 #eth0 断开删除指定路由
# The second network interface
auto eth1
iface eth1 inet static
mtu 1492
address x.x.x.x
netmask y.y.y.y
gateway z.z.z.z
dns-nameservers 223.6.6.6
恰饭,恰饭