免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 12566 | 回复: 15
打印 上一主题 下一主题

如何在unix shell中获取本机ip地址 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-10-26 10:01 |只看该作者 |倒序浏览
请教 在unix shell中如何获取本机IP地址
【注 我的/etc/host中主机ip地址对应的名称不是固定的或者说是不知到的,并不是通常的localhost】

论坛徽章:
0
2 [报告]
发表于 2003-10-26 10:30 |只看该作者

如何在unix shell中获取本机ip地址

ifconfig

论坛徽章:
0
3 [报告]
发表于 2003-10-26 10:37 |只看该作者

如何在unix shell中获取本机ip地址

ifconfig 中有好几条记录,在shell中无法区分

论坛徽章:
0
4 [报告]
发表于 2003-10-26 10:44 |只看该作者

如何在unix shell中获取本机ip地址

/sbin/ifconfig|grep "addr"

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
5 [报告]
发表于 2003-10-26 12:05 |只看该作者

如何在unix shell中获取本机ip地址

  1. ifconfig -p net0|grep inet|awk '{print $2}'
复制代码

论坛徽章:
0
6 [报告]
发表于 2003-10-26 12:49 |只看该作者

如何在unix shell中获取本机ip地址

[quote]原帖由 "bjgirl"]/sbin/ifconfig|grep "addr"[/quote 发表:

  1. [root@uclinux join]# /sbin/ifconfig |grep "addr"
  2. eth0      Link encap:Ethernet  HWaddr 00:E0:4C:8C:07:D4  
  3.           inet addr:192.168.1.22  Bcast:192.168.1.255  Mask:255.255.255.0
  4.           Interrupt:11 Base address:0x2c00
  5.           inet addr:127.0.0.1  Mask:255.0.0.0
复制代码




不准确的说。

论坛徽章:
0
7 [报告]
发表于 2003-10-26 12:51 |只看该作者

如何在unix shell中获取本机ip地址

[quote]原帖由 "admirer"]ifconfig -p net0|grep inet|awk '{print $2}'[/quote 发表:


老大,偶的LINUX  ifconfig里怎么没有这个参数?

  1. [root@uclinux join]# ifconfig -p net0|grep inet|awk '{print $2}'
  2. ifconfig: option `-p' not recognised.
  3. ifconfig: `--help' gives usage information.
复制代码

论坛徽章:
0
8 [报告]
发表于 2003-10-26 13:46 |只看该作者

如何在unix shell中获取本机ip地址

看来这个问题无法用简单的shell解决,还是在每台机器上统一设定机器名,或者在/etc/hosts中统一定义。

论坛徽章:
1
荣誉版主
日期:2011-11-23 16:44:17
9 [报告]
发表于 2003-10-26 20:22 |只看该作者

如何在unix shell中获取本机ip地址

[quote]原帖由 "yoursmile"][/quote 发表:

贴出你的ifconfig的输出看看!

论坛徽章:
0
10 [报告]
发表于 2003-10-26 23:13 |只看该作者

如何在unix shell中获取本机ip地址

原帖由 "admirer" 发表:

贴出你的ifconfig的输出看看!
  1. [root@uclinux cgi-bin]# ifconfig  
  2. eth0      Link encap:Ethernet  HWaddr 00:E0:4C:8C:07:D4  
  3.           inet addr:192.168.1.22  Bcast:192.168.1.255  Mask:255.255.255.0
  4.           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  5.           RX packets:920786 errors:21 dropped:6360 overruns:3 frame:0
  6.           TX packets:522764 errors:0 dropped:0 overruns:0 carrier:0
  7.           collisions:0 txqueuelen:100
  8.           RX bytes:121582371 (115.9 Mb)  TX bytes:719851034 (686.5 Mb)
  9.           Interrupt:11 Base address:0x2c00

  10. lo        Link encap:Local Loopback  
  11.           inet addr:127.0.0.1  Mask:255.0.0.0
  12.           UP LOOPBACK RUNNING  MTU:16436  Metric:1
  13.           RX packets:4628 errors:0 dropped:0 overruns:0 frame:0
  14.           TX packets:4628 errors:0 dropped:0 overruns:0 carrier:0
  15.           collisions:0 txqueuelen:0
  16.           RX bytes:465096 (454.1 Kb)  TX bytes:465096 (454.1 Kb)
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP