以前都是图形界面修改网卡配置,第一次使用命令行修改网卡配置,一开始以为要用ifconfig,结果发现这东西修改完重启后就丢了,不是永久的。后来才知道要修改sudo vi /etc/network/interfaces。
关键点一:为网卡配置静态IP地址
编辑文件/etc/network/interfaces,如果你不是以root用户登录请使用如下命令打开配置文件
sudo vi /etc/network/interfaces
配置文件内容如下:
auto eth0
iface eth0 inet static // 若系统现在使用的动态ip,请将dhcp改为static;
address 210.168.3.90 // 配置本机的静态IP;
gateway 192.168.3.1 // 配置默认网关的网关;
netmask 255.255.255.0 // 配置子网掩码;
dns-nameservers 192.168.1.254 8.8.8.8 // 配置DNS
#network 192.168.3.0 // 配置网络号,可以忽略;
#broadcast 192.168.3.255 // 配置网络地址,可以忽略;
iface eth0 inet static
address 192.168.1.3
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.254 8.8.8.8
dns-search foo.org bar.com
N.B.: On a machine where resolvconf has just been or is about to be installed and which
previously relied on a static /etc/resolv.conf file, the nameserver information in that
static file should be migrated to the appropriate iface stanza(s) in interfaces(5)
用dns-nameservers设置DNS即可,然后用sudo resolvconf -u来更新,cat /etc/resolv.conf就能看到更改了。
关键点二:重启网卡是的刚刚设置的地址信息生效
sudo /etc/init.d/networking restart
在ubuntu 14.04中重启服务已经不能可用了,可行的方法是sudo ifdown em1 ; sudo ifup em1 执行两条命令来重启网卡。
关键点三:配置多个ip
有些朋友出于SEO优化等需要,会在同一台VPS中绑定多个ip,下面就告诉大家如何在同一块网卡中绑定多个IP。
编辑文件/etc/network/interfaces,这个文件与关键点一的操作是同一个文件。
sudo vi /etc/network/interfaces
在原有文件的基础上添加如下的配置内容:
auto eth0:1 //注意这一块网卡的名称为eth0:1
iface eth0:1 inet static //同样配置为静态地址
address 210.168.1.91 //配置第二个地址
netmask 255.255.255.0 //配置子网掩码
#gateway x.x.x.x
#network x.x.x.x
#broadcast x.x.x.x
//以下三项最好注释掉,因为正常情况下,一台VPS是不能在两个网络中正常工作的,这也就意味一台VPS只能配置一个网关。如果配置两个网关,有可能导致系统无法正常工作。
关键点四:完成配置后,重启网卡使其生效
sudo /etc/init.d/networking restart
关键点五: 配置DNS
hosts文件的位置:/etc/hosts
只需在hosts文件中加入所需要静态解析主机名称及其对应的IP地址,即可设置本机的静态查询。
DNS配置文件的位置/etc/resolv.conf
DNS服务器的IP地址是8.8.8.8
resolv.conf内容如下:
search test.com
nameserver 8.8.8.8
14.04只编辑/etc/network/interfaces用dns-nameservers设置DNS即可,用空格分割,重启网卡后,DNS自然生效。
关键六:设置主机名称
查看当前主机的主机名称:
sudo /bin/hostname
设置当前主机的主机名称:
sudo /bin/hostname newname
系统启动时,它会从/etc/hostname来读取主机的名称。
ubuntu 修改docker cgroup systemd Ubuntu 修改网卡
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Ubuntu之修改时区/时间
查看当前时间及时区状态sudo timedatectl status# 显示当前时区为Asia/Shanghai查看当前系统时间sudo date查看当前系统时间及时区sudo date -R# 显示当前时间及对应时区,时区为“+0800”北京时区修改硬件时间修改日期格式:MM月/DD日/YYYY年sudo date -s MM/DD/YYYY修改时间:hh时:mm分:ss秒 sudo date
ubuntu修改时区 ubuntu修改时间 ubuntu修改时间及时区 ubuntu修改时区和时间 ubuntu修改系统时间 -
Docker修改容器的时间
Docker容器内系统时间不准确,可能会导致一系列问题,尤其是在依赖于时间戳进行操作的应用和服务中。
系统时间 Docker 时间同步 后端 服务器 -
Ubuntu20.04修改网卡配置
Ubuntu20.04修改网卡配置
ubuntu 参考文献 ip地址 sed 网络配置