linux 如何设置静态IP的方法

本文介绍在Linux系统中如何查看网卡及其IP地址,详细步骤指导如何将网络接口从DHCP改为静态IP地址,并手动设置DNS服务器,最后重启网络服务使更改生效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统 :Linux am335x 3.2.0 #594 Thu Oct 12 12:16:20 XJT 2017 armv7l GNU/Linux

1、查看网卡及ip地址

root@am335x:/# ifconfig

eth0      Link encap:Ethernet  HWaddr 04:79:B7:1F:75:72
          inet addr:192.168.0.15  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:813 errors:0 dropped:132 overruns:0 frame:0
          TX packets:173 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:71674 (69.9 KiB)  TX bytes:20825 (20.3 KiB)

eth1      Link encap:Ethernet  HWaddr 04:79:B7:1F:75:74
          inet addr:10.10.80.15  Bcast:10.255.255.255  Mask:255.0.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

2、修改静态IP地址

(1)原来为静态IP情况

root@am335x:/#    vi /etc/network/interface   

点击 i -修改IP-按ESC键-输入:wq-回车保存

# The loopback interface
auto lo
iface lo inet loopback

# Wireless interfaces
iface wlan0 inet dhcp
        wireless_mode managed
        wireless_essid any
        wpa-driver wext
        wpa-conf /etc/wpa_supplicant.conf

iface tiwlan0 inet dhcp
        wireless_mode managed
        wireless_essid any

iface atml0 inet dhcp

# Wired or wireless interfaces
auto eth0
#iface eth0 inet dhcp
#        pre-up /bin/grep -v -e "ip=[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" /proc/cm
iface eth0 inet static
address 192.168.1.15   //修改为 192.168.1.15
gateway 192.168.1.1    //修改
netmask 255.255.255.0

auto eth1
#iface eth1 inet dhcp
iface eth1 inet static
address 10.10.80.15
gateway 10.10.80.1
netmask 255.0.0.0

# Ethernet/RNDIS gadget (g_ether)
# ... or on host side, usbnet and random hwaddr
iface usb0 inet dhcp

(2)、原来为自动设定IP的情况

auto loiface lo inet loopbackauto 

eth0 iface eth0 inet dhcp

3、手动设置DNS服务器

打开文件 vi /etc/resolv.conf,修改内容如下 保存退出

nameserver 114.114.114.114
nameserver 192.168.1.1

4、重启网络服务

/etc/init.d/networking restart

输出

root@am335x:/# /etc/init.d/networking restart
Reconfiguring network interfaces... ifdown: misplaced option "o"
ifup: misplaced option "o"
done.

 

如果无效需断电重启

参考:https://www.cnblogs.com/yaohong/p/9483947.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dodo_code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值