參考文檔:
https://www.jb51.net/os/Ubuntu/418951.html
https://blog.csdn.net/ying1989920/article/details/48385427
添加臨時ip地址(設備重啟后不生效)
sudo ip addr add 192.168.1.104/24 dev enp0s3 //給設備 enp0s3 添加 ip 地址
sudo ip address show enp0s3 //查看配置是否生效
sudo ip addr del 192.168.1.104/24 dev enp0s3 //刪除設備 enp0s3 的 ip 地址
添加永久ip地址(設備重啟后仍然生效)
需要修改 ubuntu 下網卡的配置文件 /etc/network/interfaces ,示例如下:
auto enp0s3 // 網卡配置最開始的這一行保持不變
iface enp0s3 inet dhcp // dhcp 配置
iface enp0s3 inet static // 網卡配置靜態 ip 地址
address 192.168.1.104/24
注意:
配置多個ip地址之后可通過ping的方式驗證,或通過 'sudo ip address show <interface name>'命令查看。
通過 ifconfig 只能顯示一個 ip 地址。