目錄
- 0. 前言
- 1. 修改組態檔
- 1.1 輸入(修改)以下內容
- 1.2 示例如下
- 1.3 更新網路設定
- -- 組態檔 -- end --
- 2. 命令列修改 ifconfig - route
- 2.1 先找到需要修改的網卡
- 2.2 輸入設定IP命令
- 大體格式如下:
- 2.3 輸入設定網關命令
- 格式:
- -- ifconfig 修改 -- end --
- 3. 命令列修改 ip link - ip route
- 3.1 找到需要設定的網卡
- 3.2 設定ip地址 及 路由
- -- ip link - ip route -- end --
- 后記
0. 前言
可以臨時設定,也可以修改組態檔
1. 修改組態檔
# 打開 配置IP的檔案 路徑如下
sudo vi /etc/netplan/01-network-manager-all.yaml
1.1 輸入(修改)以下內容
# This is the network config written by 'subiquity'
network:
ethernets:
ens0:
dhcp4: false
addresses: [192.168.1.123/24]
gateway4: 192.168.1.1
ens1:
dhcp4: false
addresses: [192.168.1.124/24]
gateway4: 192.168.1.1
version: 2
注意: 這是修改為靜態IP的方式,所以上面的 DHCP4:最好改成 FALSE,防止自動獲取IP,導致IP又變了
1.2 示例如下

1.3 更新網路設定
/etc/init.d/openibd restart
-- 組態檔 -- end --
2. 命令列修改 ifconfig - route
根據ifconfig 命令,這個命令一般系統自帶,也可以后期安裝
sudo apt install net-tools
2.1 先找到需要修改的網卡
ifconfig
2.2 輸入設定IP命令
sudo ifconfig ens33 192.168.1.123/24 up
大體格式如下:
sudo權限 ifconfig 網卡名 IP地址/掩碼 up
2.3 輸入設定網關命令
sudo route add default gw 192.168.1.1
格式:
sudo權限 route add default gw 網關地址
-- ifconfig 修改 -- end --
由于 ifconfig 在Ubuntu 里大部分是通過后期安裝 net-tools 包,安裝上的 ,剛安裝完的系統可能沒有這個 net-tools 包,所以 ifconfig 命令無法使用
但 ip 命令是 自帶的
3. 命令列修改 ip link - ip route
3.1 找到需要設定的網卡
ip a 或 ip addr
(一毛一樣,畢竟是一個命令.....哈哈)
3.2 設定ip地址 及 路由
ip link set eth0 up # eth0 是前面的 網卡埠名
ip link show eth0 # 這個 eth0 也是
ip addr add <IP地址> dev eth0 # 這個也是
ip route add default via <網關>
-- ip link - ip route -- end --
后記
如果需要長久設定 可以用 rc.local ,把需要的命令設定進去,也能達到 最開始 修改組態檔的效果
rc.loacl 啟用方式 如下
CSDN-Ubuntu rc.local 的開啟與配置-也是我寫的
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/506102.html
標籤:其他


