Android shell命令查询ip,网关,DNS

查看所有网络信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C:\>adb shell
root@android:/ # netcfg
netcfg
ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00
gre0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00
eth0     UP                               192.168.0.180/24  0x00001043 00:00:00:
ec:0a:00
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00
lo       UP                                   127.0.0.1/8   0x00000049 00:00:00:
00:00:00
tunl0    DOWN                                   0.0.0.0/0   0x00000080 00:00:00:
00:00:00

 查看 eth0

1
2
3
root@android:/ # ifconfig eth0
ifconfig eth0
eth0: ip 192.168.0.180 mask 255.255.255.0 flags [up broadcast running multicast]

 查看DNS

1
2
3
4
5
6
7
root@android:/ # getprop net.eth0.dns1
getprop net.eth0.dns1
8.8.8.8
 
root@android:/ # getprop net.eth0.dns2
getprop net.eth0.dns2
8.8.4.4

 查看ip

1
2
3
4
5
6
root@android:/ # ifconfig eth0 192.168.0.173 netmask 255.255.255.0
ifconfig eth0 192.168.0.173 netmask 255.255.255.0
 
root@android:/ # ifconfig eth0
ifconfig eth0
eth0: ip 192.168.0.173 mask 255.255.255.0 flags [up broadcast running multicast]

 设置网关

1
2
root@android:/ # route add default gw 192.168.0.1 dev eth0
route add default gw 192.168.0.1 dev eth0

 添加dns

1
2
3
4
5
root@android:/ # setprop net.eth0.dns1 8.8.8.8
setprop net.eth0.dns1 8.8.8.8
 
root@android:/ # setprop net.eth0.dns2 8.8.4.4
setprop net.eth0.dns2 8.8.4.4

 查询eth0配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
root@android:/ # getprop | grep eth0
getprop | grep eth0
[dhcp.eth0.dns1]: [192.168.0.1]
[dhcp.eth0.dns2]: []
[dhcp.eth0.dns3]: []
[dhcp.eth0.dns4]: []
[dhcp.eth0.gateway]: [192.168.0.1]
[dhcp.eth0.ipaddress]: [192.168.0.180]
[dhcp.eth0.leasetime]: [3600]
[dhcp.eth0.mask]: [255.255.255.0]
[dhcp.eth0.pid]: [13800]
[dhcp.eth0.reason]: [PREINIT]
[dhcp.eth0.result]: [failed]
[dhcp.eth0.server]: [192.168.0.1]
[dhcp.eth0.vendorInfo]: []
[net.change]: [net.eth0.dns2]
[net.eth0.dns1]: [8.8.8.8]
[net.eth0.dns2]: [8.8.4.4]

 ifconfig eth0配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
以下各值常见于所有的基本配置文件中:
     * DEVICE=name,这里name是物理设备的名字(动态分配的PPP设备应当除外,
       它的名字是“逻辑名”。
     * IPADDR=addr, 这里addr是IP地址。
     * NETMASK=mask, 这里mask是网络掩码。
     * NETWORK=addr, 这里addr是网络地址。
     * BROADCAST=addr, 这里addr是广播地址。
     * GATEWAY=addr, 这里addr是网关地址。
     * ONBOOT=answer, 这里answer取下列值之一:
           o yes -- 该设备将在boot时被激活。
           o no -- 该设备不在boot时激活。
     * USERCTL=answer, 这里answer取下列值之一:
           o yes --非root用户可以控制该设备。
           o no -- 非root用户不允许控制该设备。
     * BOOTPROTO=proto, 这里proto取下列值之一:
           o none -- 不使用boot时协议。
           o bootp -- 使用bootp协议。
           o dhcp --使用dhcp协议。
 
终端:查询IP地址: ifconfig -a
 修改局域网IP:
 1.以 root 登录
 2.修改配置文件
 /etc/sysconfig/network-scripts/ifcfg-eth0
 
 文件内容如下:
 \DEVICE=eth0
 HWADDR=00:0C:29:A2:8C:B2
 ONBOOT=yes
 TYPE=Ethernet
 NETMASK=255.255.255.0
 IPADDR=192.168.1.11 -> 修改为 192.168.1.12
 GATEWAY=192.168.1.1
 
 reboot
ifconfig eth0 新ip 然后编辑/etc/sysconfig/network-scripts/ifcfg-eth0,修改ip
ifconfig eth0 新IP
 
然后编辑/etc/sysconfig/network-scrIPts/ifcfg-eth0,修改IP
 
一、修改IP地址
 
[aeolus@db1 network-scrIPts]$ vi ifcfg-eth0
 
DEVICE=eth0
 
ONBOOT=yes
 
BOOTPROTO=static
 
IPADDR=219.136.241.211
 
NETMASK=255.255.255.128
 
GATEWAY=219.136.241.254
 
二、修改网关
 
vi /etc/sysconfig/network
 
NETWORKING=yes
 
HOSTNAME=Aaron
 
GATEWAY=192.168.1.1
 
三、修改DNS
 
[aeolus@db1 etc]$ vi resolv.conf
 
nameserver 202.96.128.68
 
nameserver 219.136.241.206
 
 
四、重新启动网络配置
 
/etc/init.d/network restart
 
 
修改IP地址
 
即时生效:
 
# ifconfig eth0 192.168.0.20 netmask 255.255.255.0
 
启动生效:
 
修改/etc/sysconfig/network-scrIPts/ifcfg-eth0
 
修改default gateway
 
即时生效:
 
# route add default gw 192.168.0.254
 
启动生效:
 
修改/etc/sysconfig/network-scrIPts/ifcfg-eth0
 
修改DNS
 
修改/etc/resolv.conf
 
修改后可即时生效,启动同样有效
 
修改host name
 
即时生效:
 
# hostname fc2
 
启动生效:
 
修改/etc/sysconfig/networknetcfg eth0 dhcp

 

posted @   一样菜  阅读(35064)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示