在 CLI(命令行界面)配置服务器网络的方法取决于你使用的 操作系统。下面分别介绍 Linux(最常见) 和 Windows Server 的常用方式。
ip addr
ip route
配置 IP 地址
ip addr add 192.168.1.10/24 dev eth0
配置网关
ip route add default via 192.168.1.1
配置 DNS
echo "nameserver 8.8.8.8" > /etc/resolv.conf
sudo nano /etc/netplan/00-installer-config.yaml
示例:
network:
version: 2
ethernets:
eth0:
addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
应用配置:
sudo netplan apply
nmcli connection modify eth0 \
ipv4.addresses 192.168.1.10/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns 8.8.8.8 \
ipv4.method manual
nmcli connection up eth0
ping 8.8.8.8
ping www.baidu.com
Get-NetAdapter
New-NetIPAddress `
-InterfaceAlias "Ethernet" `
-IPAddress 192.168.1.10 `
-PrefixLength 24 `
-DefaultGateway 192.168.1.1
Set-DnsClientServerAddress `
-InterfaceAlias "Ethernet" `
-ServerAddresses ("8.8.8.8","1.1.1.1")
ipconfig /all
ping 8.8.8.8
如果你能告诉我:
我可以给你更精确的配置命令。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。