ubuntu配置静态ip

来源:互联网 发布:linux vi退出不了 编辑:程序博客网 时间:2024/04/29 23:25

配置静态ip

网络配置信息存储在/etc/network/interfaces 文件中
sudo vi /etc/network/interfaces
我用vi打开,我的文件显示如下内容:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

我的网络配置文件中只有一个环回地址,即127.0.0.1。在下面添加:

auto eth0                            #指明网卡eth0在系统启动时自动加载
iface eth0 inet static             #指明eth0采用ipv4地址,inet表示ipv4地址,inet6表示ipv6地址;
static表示静态,dhcp表示动态
address 172.22.112.13        #静态ip
netmask 255.255.255.128   #子网掩码
gateway 172.22.112.1         #网关地址

:wq                                      #保存退出


常用命令

设置ip地址:sudo ifconfig eth0 172.22.0.121 netmask 255.255.0.0
设置网关:route add default gw 172.22.0.254
修改 DNS:
zhouyixing@MS-7798:~/Workspace/g870d/g870d_kernel$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 172.18.0.1
nameserver 172.18.0.3
原创粉丝点击