一、ubuntu18 網卡配置 永久靜態路由 server版
ubuntu系統用的比較少,從ubuntu 18 server開始使用netplan管理卡; 紀錄一下網卡配置,和靜態路由配置;
netpan 命令幫助
root@fjgdwl_ubuntu_template:~# netplan help usage: /usr/sbin/netplan [-h] [--debug] ... Network configuration in YAML optional arguments: -h, --help show this help message and exit --debug Enable debug messages 使用debug方式運行,前台顯示運行日志;例 netplan --debug apply Available commands: help Show this help message apply Apply current netplan config to running system 運行新的配置到服務器;似重啟網卡 generate Generate backend specific configuration files from 生成配置文件 (/etc/netplan/ 可能沒有yaml 文件) /etc/netplan/*.yaml info Show current netplan version and available features 顯示版本 ip Retrieve IP information from the system try Try to apply a new netplan config to running system, with 嘗試驗證配置文件 automatic rollback
配置:
root@ubuntu_18:~# vim /etc/netplan/tools-netcfgv4.yaml
# This file generated by castools, describes the ipv4 network interfaces available on your system network: version: 2 renderer: networkd ethernets: #hwaddr: 0c:da:41:1d:bf:44 ens3: addresses: - 192.168.136.6/28 routes: - to: 10.166.0.0/15 via: 192.168.136.1 - to: 10.168.0.0/13 via: 192.168.136.1 #gateway4: 192.168.136.1 #hwaddr: 0c:da:41:1d:d0:65 ens10: addresses: - 192.168.137.6/28 gateway4: 192.168.137.1
root@fjgdwl_ubuntu_template:~# netplan apply 重啟網卡
=============================================================================================
二、ubuntu18 網卡配置 永久靜態路由 desktop版
碰到服務器第三方裝的系統。
網卡配置是這樣的,通過查看系統版本發現裝成了ubuntu desktop版本,是用圖形界面配置的網絡 默認使用了NetworkManager由於遠程訪問不能斷網通過 grep -r "10.110.5.2" * 找到了網卡配置文件在</etc/NetworkManager/system-connections/有線連接 2>。
看配置文件毫無頭腦;試了下centos配置網卡的命令<nmtui>居然可以;
#nmtui 按步驟點擊 可以添加路由,保存之后會同步到配置文件中,並且不需要重啟網卡;
黃色部分是新添加的路由
root@huawei-2488-V5:/etc# cat NetworkManager/system-connections/有線連接\ 2 [connection] id=有線連接 2 uuid=c49242d8-3043-39bd-a0bc-32fd645767db type=ethernet autoconnect-priority=-999 permissions= timestamp=1627875689 [ethernet] mac-address=F0:33:E5:1B:A5:DC mac-address-blacklist= [ipv4] address1=10.10.5.2/29 dns-search= ignore-auto-routes=true method=manual route1=10.172.0.0/14,10.10.5.1 route2=10.180.0.0/15,10.10.5.1 route3=10.218.0.0/15,10.10.5.1 route4=10.220.0.0/14,10.10.5.1 route5=10.224.0.0/14,10.10.5.1 [ipv6] addr-gen-mode=stable-privacy dns-search= method=auto