ubuntu linux修改ip地址命令,如何在ubuntu桌面通过命令行,更改ip地址
问题在Ubuntu桌面13.04中更改/etc/network/interfaces文件,不能更改ip地址,将DHCP转换为静态网络接口配置也不行。修改文件后我尝试sudo service networking restart答案1默认情况下,Ubuntu (Network Manager)忽略/etc/network/interfaces文件,要使所做的更改生效,请执行以下命令:sudo ifd
问题
在Ubuntu桌面13.04中更改/etc/network/interfaces文件,不能更改ip地址,将DHCP转换为静态网络接口配置也不行。修改文件后我尝试sudo service networking restart
答案1
默认情况下,Ubuntu (Network Manager)忽略/etc/network/interfaces文件,要使所做的更改生效,请执行以下命令:sudo ifdown wlan0
sudo ifup wlan0
假设wlan0是你编辑的接口,一旦你这样做了,wlan0就会在/etc/network/interfaces中给出你的设置。
因为你是通过SSH连接的,你可以尝试以下操作:
编辑/etc/NetworkManager/NetworkManager.conf 将ifdown managed更改为false:[ifupdown]
managed=false
答案2
试试这个,按键盘上的ctrl+alt+t打开终端,打开后,运行下面的命令:sudo -i
gedit /etc/network/interfaces
一旦完成并退出
添加这里行dhcp模式auto eth0
iface eth0 inet dhcp
静态模式auto eth0
iface eth0 inet static
address xxx.xxx.xxx.xxx
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx
完成后保存文件,然后:sudo service resolvconf restart
答案3
可以使用以下脚本更改ip地址:
用Ctrl+Alt+t打开终端并键入以下命令:sudo vi /etc/network/interfaces
或者gksudo gedit /etc/network/interfaces
查找eth部分并设置IP地址,如下所示:auto eth0
iface eth0 inet static
address 192.168.2.1
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
保存并管理文件,完成后,重新启动网络:$ sudo /etc/init.d/networking restart
使用以下命令验证新的IP地址:$ ifconfig eth0
$ ifconfig
答案4
在所有接口上显示当前IP (ip addr )n2:~$ ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:e0:4c:6d:0a:49 brd ff:ff:ff:ff:ff:ff
3: wlan0: mtu 1500 qdisc mq state UP qlen 1000
link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff
inet 172.22.0.221/24 brd 172.22.0.255 scope global wlan0
inet6 fe80::76ea:3aff:fead:2e00/64 scope link
valid_lft forever preferred_lft forever
将IP地址添加到无线接口(ip addr add )n2:~$ sudo ip a a 10.0.0.56/24 dev wlan0
[sudo] password for bensley:
再次显示IP地址,注意wlan +上的附加IP (ip addr )n2:~$ ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:e0:4c:6d:0a:49 brd ff:ff:ff:ff:ff:ff
3: wlan0: mtu 1500 qdisc mq state UP qlen 1000
link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff
inet 172.22.0.221/24 brd 172.22.0.255 scope global wlan0
inet 10.0.0.56/24 scope global wlan0
inet6 fe80::76ea:3aff:fead:2e00/64 scope link
valid_lft forever preferred_lft forever
显示接口的链接状态(ip link )n2:~$ ip l
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:e0:4c:6d:0a:49 brd ff:ff:ff:ff:ff:ff
3: wlan0: mtu 1500 qdisc mq state UP qlen 1000
link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff
从无线接口中删除第二个IP地址(ip addr delete )n2:~$ sudo ip a del 10.0.0.56/24 dev wlan0
只显示wlan0要检查的ip地址(ip addr show wlan0 )n2:~$ ip a s wlan0
3: wlan0: mtu 1500 qdisc mq state UP qlen 1000
link/ether 74:ea:3a:ad:2e:00 brd ff:ff:ff:ff:ff:ff
inet 172.22.0.221/24 brd 172.22.0.255 scope global wlan0
inet6 fe80::76ea:3aff:fead:2e00/64 scope link
valid_lft forever preferred_lft forever
同样的命令可以用来删除当前IP,然后172.22.0.221添加另一个,下面是一些命令,之后,我还需要添加新的默认路由;n2:~$ ip r s
default via 172.22.0.1 dev wlan0 proto static
169.254.0.0/16 dev wlan0 scope link metric 1000
172.22.0.0/24 dev wlan0 proto kernel scope link src 172.22.0.221 metric 2
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
ip a del 172.22.0.221/24 dev wlan0
ip a a 172.22.0.10/24 dev wlan
ip r a default via 172.22.0.1
# Re-add the same default route ^ via the same default gateway
答案5在/etc/NetworkManager/NetworkManager.conf中禁用网络连接的图形管理
收集有关静态IP的信息(接口,要使用的IP,默认网关,子网,DNS)
修改/etc/network/interfaces
重新启动网络和网络管理器服务
答案6
这是正确的方法。sudo ifconfig eth0 down
sudo ifconfig eth0
sudo ifconfig eth0 up
相关文章
更多推荐
所有评论(0)