您的位置:首页 > 理论基础 > 计算机网络

Ubuntu server的网络配置,静态IP地址、默认路由以及dns等网络参数配置命令

2015-06-11 00:00 901 查看
摘要: 习惯了桌面版linux系统的图形界面管理工具,管理配置只有shell的linux server版系统,感觉非常茫然,无从下手。把一些常用的网络配置命令收集起来,方便日后查阅。

ifconfig -a

显示网络配置情况,借此查询网络接口name,一个网卡时,network name 一般是: eth0

临时生效,重启丢失的网络配置命令:
设置静态ip地址

sudo ifconfig eth0 10.0.0.100 netmask 255.255.255.0

设置缺省路由:

sudo route add default gw 10.0.0.1 eth0

显示路由表:

route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.0.0        0.0.0.0         255.255.255.0   U     1      0        0 eth0
0.0.0.0         10.0.0.1        0.0.0.0         UG    0      0        0 eth0

设置dns,修改 /etc/resolv.conf 保存后立即生效

nameserver 8.8.8.8
nameserver 8.8.4.4

上述配置的网络环境,是即时生效,重启后失效。或者使用 ip addr flush eth0 ,也可不重启而令配置失效 ip addr flush eth0
禁用和启用网卡命令分别是:

sudo ifdown eth0
sudo ifup eth0

令网络配置信息永久有效,把如下内容编辑到 /etc/network/interfaces 网络配置文件中

iface eth0 inet static
address 192.168.3.3
netmask 255.255.255.0
gateway 192.168.3.1
dns-search example.com sales.example.com dev.example.com
dns-nameservers 8.8.8.8 114.114.114

其中 dns-search example.com sales.example.com dev.example.com 可以删除不要。
dns-search 的意义是:

If you try to ping a host with the name of server1, your system will automatically query DNS for its Fully Qualified Domain Name (FQDN) in the following order:
server1.example.com
server1.sales.example.com
server1.dev.example.com
If no matches are found, the DNS server will provide a result of notfound and the DNS query will fail.

上述内容,整理自官方文档 Ubuntu net work configuation
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: