0. 前言 可以臨時設置,也可以修改配置文件 1. 修改配置文件 # 打開 配置IP的文件 路徑如下 sudo vi /etc/netplan/01-network-manager-all.yaml 1.1 輸入(修改)以下內容 # This is the network config writte ...
目錄
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 的開啟與配置-也是我寫的