LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1283|回复: 8

如何知道本机的IP地址啊?

[复制链接]
发表于 2011-1-20 02:55:57 | 显示全部楼层 |阅读模式
当没有权限使用ifconfig的时候,如何知道本机的IP地址啊?

username$ /sbin/ifconfig
Warning: cannot open /proc/net/dev (No such file or directory). Limited output.
发表于 2011-1-20 13:55:50 | 显示全部楼层
根据你所用的Linux发行版查看相应的/etc/下面的配置文件试试。
回复 支持 反对

使用道具 举报

发表于 2011-1-20 14:00:03 | 显示全部楼层
访问formyip.com

如果是内网,就用lshw

例如:
lshw | grep 192.168
WARNING: you should run this program as super-user.
                configuration: broadcast=yes driver=r8169 driverversion=2.3LK-NAPI ip=192.168.5.100 latency=0 multicast=yes
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
delectate@delectate:~$
回复 支持 反对

使用道具 举报

 楼主| 发表于 2011-1-22 03:50:43 | 显示全部楼层
Post by delectate;2126199
访问formyip.com

如果是内网,就用lshw

例如:
lshw | grep 192.168
WARNING: you should run this program as super-user.
                configuration: broadcast=yes driver=r8169 driverversion=2.3LK-NAPI ip=192.168.5.100 latency=0 multicast=yes
WARNING: output may be incomplete or inaccurate, you should run this program as super-user.
delectate@delectate:~$

-bash: lshw: command not found
回复 支持 反对

使用道具 举报

发表于 2011-1-22 13:33:31 | 显示全部楼层


sudo pacman -S lshw
回复 支持 反对

使用道具 举报

发表于 2011-2-5 16:52:14 | 显示全部楼层
内网
/sbin/ifconfig
外网
curl ifconfig.me
回复 支持 反对

使用道具 举报

发表于 2011-2-5 17:47:09 | 显示全部楼层
楼上牛,学习了

curl ifconfig.me
回复 支持 反对

使用道具 举报

发表于 2011-2-18 07:25:33 | 显示全部楼层
不知道你是要在脚本里用还是就是想知道IP。
就说内网的。
如果 ifconfig, lshw都不行试试这个笨法子:

$ip route get 1.1.1.1|sed -rn '1 s/.*src (([0-9]+.){3}[0-9]+).*/\1/p'

或者就netstat一下,看tcp对应的local那一列。
回复 支持 反对

使用道具 举报

发表于 2011-2-19 22:15:03 | 显示全部楼层
调用ip命令:
  1. $ ip addr show eth0
  2. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  3.     link/ether 48:5b:39:8a:69:d9 brd ff:ff:ff:ff:ff:ff
  4.     inet 219.218.108.10/23 brd 219.218.109.255 scope global eth0
  5.     inet6 2001:da8:7000:4f:4a5b:39ff:fe8a:69d9/64 scope global dynamic
  6.        valid_lft 2591908sec preferred_lft 604708sec
  7.     inet6 fe80::4a5b:39ff:fe8a:69d9/64 scope link
  8.        valid_lft forever preferred_lft forever
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表