由于項(xiàng)目需要,需要在kali上添加一條路由,并且保證重啟后仍然生效。
經(jīng)查找發(fā)現(xiàn)有兩種可行的方法:
1、修改/etc/network/interfaces配置文件,添加一行,如:
up route add -net 10.105.10.0 netmask 255.255.255.255 gw 192.168.1.1 eth0
-net指這是一條網(wǎng)絡(luò)路由(ip地址主機(jī)位為0)
gw指下一跳
2、修改rc.local,添加:
route add -net 192.168.114.0/24 dev eth0
或
route add -net 192.168.114.0/24 gw 192.168.3.254
那么,為了保證重啟仍然生效需要將它寫入rc.local配置文件。
--------------------------------------------分割線--------------------------------------------------------
第一個方法添加路由后,使用route命令查看路由表;的確是添加了,但實(shí)際測試中發(fā)現(xiàn)沒有起作用,目標(biāo)仍然不可訪問。(玄學(xué)問題)
第二個方法遇到一個問題,kali把rc.local“ 服務(wù)化”了,并沒有rc.local配置文件怎么辦呢?
解決方法:
vim /etc/systemd/system/rc-local.service
將內(nèi)容替換為
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
然后
touch /etc/rc.local(正常情況下/etc/rc.local并不是配置文件本身,而是/etc/rc.d/rc.local的軟連接;但徒增麻煩不建議那么做)
記得賦予執(zhí)行權(quán)限
chmod +x /etc/rc.local
vim /etc/rc.local
添加
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
exit 0
插入腳本就在exit 0之前即可
重啟rc-local服務(wù)
systemctl restart rc-local.service
設(shè)置開機(jī)自啟動
systemctl enable rc-local
---------------------------------------你以為這樣就結(jié)束了?-------------------------------------------
我將添加路由的shell命令添加到rc.local之后重啟發(fā)現(xiàn),并沒有成功添加路由;
執(zhí)行systemctl status rc-local.service發(fā)現(xiàn)報(bào)錯顯示“網(wǎng)絡(luò)未啟動”。。。。
在檢查了各種錯誤之后我斷定,是啟動優(yōu)先級沒有起作用
無奈曲線解決,在啟動腳本里添加sleep命令延遲執(zhí)行腳本
詳見我的shell腳本:
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
/usr/local/bin/route-eth0
exit 0
/usr/local/bin/route-eth0:
#!/bin/bash
sleep 15s
route add -net 192.168.114.0/24 dev eth0
exit0
最終問題解決,目的是給更多人帶來方便。