FreeBSD下增进静态路由的行动
1.手工添加
# route add -net 192.168.2.0/24 192.168.1.2
2. 通过rc.conf永世 设置
# Add static route
static_routes="net1 net2"
route_net1="-net 192.168.0.0/24 192.168.0.1"
route_net2="-net 192.168.1.0/24 192.168.1.1"
ifconfig_eth0="inet 192.168.1.253 netmask 255.255.255.0"
defaultrouter="192.168.1.254"
路由的属性符号 和它们的寄义 的一个简表:
U Up: 路由处于活动状况 。
H Host: 路由方针 是单个主机。
G Gateway: 全部 发到方针地的网络传到这一长途 体系 上, 并由它决议 末了 发到那边。
S Static: 这个路由是手工设置 的,不是由体系 主动 天生 的。
C Clone: 天生 一个新的路由, 通过这个路由我们可以毗连 上这些机子。 这种范例 的路由通常用于内地 网络。
W WasCloned: 指明一个路由——它是基于内地 区 域网络 (克隆) 路由主动 设置 的。
L Link: 路由涉及到了以太网硬件。
Task: View / Display FreeBSD Routing Table
Use netstat command with -r option:
$ netstat -r
Output:
$ netstat -rn
Routing tables
Internet:
Destination Gateway Flags Refs Use Netif Expire
default 61.221.xx.yy UGS 0 247 em1
10 10.10.110.5 UGS 0 50 em0
10.10.110/26 link#1 UC 0 0 em0
10.10.110.5 00:1b:0d:e6:58:40 UHLW 2 0 em0 1145
61.221.xx.yy/29 link#2 UC 0 0 em1
61.221.xx.yy 00:1b:0d:e6:57:c0 UHLW 2 0 em1 1055
61.221.xx/24 link#2 UC 0 0 em1
127.0.0.1 127.0.0.1 UH 0 0 lo0
The first two line displays default routes.
Task: FreeBSD Set a default route
All network packets that cannot be sent according to the previous entries of the routing table are sent through the following default gateway:
# route add default 192.168.1.254
How do I save routing information to a configuration file?
If you reboot FreeBSD box, the routing configuration will be lost i.e. the routing information will not persist. You need to edit /etc/rc.conf file to set defaultroute:
# vi /etc/rc.conf
Set default route by editing defaultrouter variable:
defaultrouter="192.168.1.254"
Save and close the file.
Task: Start and Stop FreeBSD Configured Interfaces
To apply changes to a configuration file, . The following command will also update routing information:
# /etc/rc.d/netif restart
# /etc/rc.d/netif stop
# /etc/rc.d/netif start