
我正在嘗試更改預設路由到 eth2 我目前的路由 -no/p--
Destination Gateway Genmask Flags Metric Ref Use Iface
10.235.4.0 * 255.255.255.0 U 0 0 0 eth3
10.235.3.0 * 255.255.255.0 U 0 0 0 eth2
10.235.2.0 * 255.255.255.0 U 0 0 0 eth0
169.X.0.0 * 255.255.0.0 U 0 0 0 eth3
default 10.235.4.1 0.0.0.0 UG 0 0 0 eth3
IP ro sh - 輸出
# ip ro sh
10.235.4.0/24 dev eth3 proto kernel scope link src 10.235.4.21
10.235.3.0/24 dev eth2 proto kernel scope link src 10.235.3.21
10.235.2.0/24 dev eth0 proto kernel scope link src 10.235.2.21
169.x.0.0/16 dev eth3 scope link
default via 10.235.4.1 dev eth3
我想做的是
> Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.235.4.0 * 255.255.255.0 U 0 0 0 eth3
10.235.3.0 * 255.255.255.0 U 0 0 0 eth2
10.235.2.0 * 255.255.255.0 U 0 0 0 eth0
169.x.0.0 * 255.255.0.0 U 0 0 0 eth3
default 10.235.2.1 0.0.0.0 UG 0 0 0 eth2
我嘗試了不同的方法a>在/etc/sysconfig/network.conf中加入“gatewaydev=eth2”。
b> 透過指令新增路由 eth2 並刪除 eth3 路由條目。
服務網路重新啟動後,它會回到第一個輸出。
幫我謝謝
答案1
只需在 /etc/sysconfig/network 中新增/取代預設閘道 IP 位址
GATEWAY=10.235.2.1
然後重啟newtwork服務
# service network restart
答案2
10.235.2.0
您必須先取得網路位址eth2
,然後才能變更GATEWAY=
值。
答案3
開啟/etc/sysconfig/network檔案:
#vi /etc/sysconfig/network
設定 GATEWAY={路由器 IP}
GATEWAY=10.235.2.1
您需要重新啟動網路服務:
# /etc/init.d/networking restart
答案4
我傾向於將網關新增至適當介面的 /etc/sysconfig/network-scripts/ifcfg-ethX 設定檔中,例如:
BOOTPROTO=none
DEVICE=eth0
ONBOOT=yes
SLAVE=no
IPADDR=10.20.30.40
NETMASK=255.255.255.0
GATEWAY=10.20.30.1
USERCTL=no
BROADCAST=10.20.30.255
我傾向於不是將其放入 /etc/sysconfig/network 中,當然可以。我做了很多非常複雜的綁定配置,如果所有文件都放在一個地方,就會變得更容易。
如果您像我一樣這樣做,請勿在其他 IFCFG 檔案中聲明網關介面。它會按順序讀取它們,每次都會重置網關,並且您不會得到預期的行為。