免费注册 查看新帖 |

Chinaunix

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

Solaris 指定通讯接口方法----分享 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-06-25 11:05 |只看该作者 |倒序浏览
大家在工作中有可能遇到这样的问题,一台服务器存在两个及两个以上IP地址(物理IP和业务IP),那么如何控制业务程序使用业务IP进行通讯呢。下面将通过两个实例来讲解如何根据自己需要限制接口通信。希望对大家有所帮助:

一、环境
  1. root@e5kd6 # more /etc/defaultrouter
  2. 192.168.0.129

  3. root@e5kd6 # more /etc/netmasks
  4. 192.168.0.0      255.255.255.0

  5. root@e5kd6 # netstat -rn

  6. Routing Table: IPv4
  7.   Destination           Gateway           Flags  Ref   Use   Interface
  8. -------------------- -------------------- ----- ----- ------ ---------
  9. 192.168.0.0           192.168.0.59          U         1      0  ge0
  10. default              192.168.0.129         UG        1    194  
  11. 127.0.0.1            127.0.0.1            UH       101964416  lo0

  12. root@e5kd6 # ifconfig -a

  13. ge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 6
  14.         inet 192.168.0.59 netmask ffffff00 broadcast 192.168.0.255
  15.         ether 8:0:20:ff:1b:5c
复制代码

评分

参与人数 1可用积分 +5 收起 理由
zhmzhouming + 5 我很赞同

查看全部评分

论坛徽章:
0
2 [报告]
发表于 2010-06-25 11:06 |只看该作者
添加子接口地址,用于业务IP:
  1. root@e5kd6 # ifconfig ge0 addif 192.168.0.57 netmask + broadcast + up
  2. Created new logical interface ge0:1
  3. Setting netmask of ge0:1 to 255.255.255.0

  4. root@e5kd6 # ifconfig -a
  5. lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
  6.         inet 127.0.0.1 netmask ff000000
  7. ge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 6
  8.         inet 192.168.0.59 netmask ffffff00 broadcast 192.168.0.255
  9.         ether 8:0:20:ff:1b:5c
  10. ge0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 6
  11.         inet 192.168.0.57 netmask ffffff00 broadcast 192.168.0.255

  12. root@e5kd6 # netstat -rn

  13. Routing Table: IPv4
  14.   Destination           Gateway           Flags  Ref   Use   Interface
  15. -------------------- -------------------- ----- ----- ------ ---------
  16. 192.168.0.0           192.168.0.59          U         1      0  ge0
  17. 192.168.0.0           192.168.0.57          U         1      0  ge0:1
  18. default              192.168.0.129         UG        1    196  
  19. 127.0.0.1            127.0.0.1            UH       101964707  lo0

  20. root@e5kd6 # traceroute 10.109.109.33
  21. traceroute: Warning: Multiple interfaces found; using 192.168.0.59 @ ge0
  22. traceroute to 10.109.109.33 (10.109.109.33), 30 hops max, 40 byte packets
  23. 1  192.168.0.2 (192.168.0.2)  1.321 ms  0.397 ms  0.365 ms
  24. 2  10.109.109.33 (10.109.109.33)  0.358 ms  0.333 ms  0.315 ms
复制代码

论坛徽章:
0
3 [报告]
发表于 2010-06-25 11:12 |只看该作者
本帖最后由 rusty_rui 于 2010-06-25 11:25 编辑

配置1、期望使用192.168.0.57用于服务器间通信,配置过Sun Cluster的同仁对此应该不陌生。那就是使用deprecated参数:
   
deprecated
           Marks the address as a deprecated  address.  Addresses
           marked  as  deprecated  will  not  be  used  as source
           address for outbound packets unless either  there  are
           no  other addresses available on this interface or the
           application has bound to this address explicitly.  The
           status  display shows DEPRECATED as part of flags. See
           INTERFACE FLAGS for information on the flags supported
           by ifconfig.



对需要进行限制通信的接口使用此参数,使用此参数的接口地址原则上不参与主动通信,仅当没有其他可用的接口地址用于通信时才承担主动通信任务。可以使用 "-deprecated"参数取消此限制。注:使用deprecated参数的地址,被动访问还是要提供服务的。

  此测试中计划使用192.168.0.57作为业务地址,那么我们需要限制ge0端口地址192.168.0.59:
  1. root@e5kd6 # ifconfig ge0 deprecated
  2. [b]root@e5kd6 # ifconfig -a[/b]
  3. lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
  4.         inet 127.0.0.1 netmask ff000000
  5. ge0: flags=1040843<UP,BROADCAST,RUNNING,MULTICAST,[b]DEPRECATED[/b],IPv4> mtu 1500 index 6
  6.         inet 192.168.0.59 netmask ffffff00 broadcast 192.168.0.255
  7.         ether 8:0:20:ff:1b:5c
  8. ge0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 6
  9.         inet 192.168.0.57 netmask ffffff00 broadcast 192.168.0.255

  10. root@e5kd6 # traceroute 10.109.109.33
  11. traceroute: Warning: Multiple interfaces found; [b]using 192.168.0.57 @ ge0:1[/b]
  12. traceroute to 10.109.109.33 (10.109.109.33), 30 hops max, 40 byte packets
  13. 1  192.168.0.3 (192.168.0.3)  1.780 ms  0.385 ms  0.344 ms
  14. 2  10.109.109.33 (10.109.109.33)  0.398 ms  0.310 ms  0.308 ms

  15.           已经按照预定端口ge0:1进行通讯

  16. root@e5kd6 # netstat -rn

  17. Routing Table: IPv4
  18.   Destination           Gateway           Flags  Ref   Use   Interface
  19. -------------------- -------------------- ----- ----- ------ ---------
  20. 192.168.0.0           192.168.0.57          U         1      1  ge0:1
  21. 192.168.0.0           192.168.0.57          U         1      0  ge0
  22. default              192.168.0.129         UG        1    201  
  23. 127.0.0.1            127.0.0.1            UH       101967996  lo0
复制代码

论坛徽章:
0
4 [报告]
发表于 2010-06-25 11:17 |只看该作者
配置2、设置接口point-to-point通信,在主机上设置用于专项针对某一个地址通信的。此方法虽然我们可以采用设置路由的方式实现。
  此测试计划在ge0:1接口专项用于通讯至10.109.109.33地址:

环境:
  1. root@e5kd6 # ifconfig -a
  2. lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
  3.         inet 127.0.0.1 netmask ff000000
  4. ge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 6
  5.         inet 192.168.0.59 netmask ffffff00 broadcast 192.168.0.255
  6.         ether 8:0:20:ff:1b:5c
  7. ge0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 6
  8.         inet 192.168.0.57 netmask ffffff00 broadcast 192.168.0.255

  9. root@e5kd6 # netstat -rn

  10. Routing Table: IPv4
  11.   Destination           Gateway           Flags  Ref   Use   Interface
  12. -------------------- -------------------- ----- ----- ------ ---------
  13. 192.168.0.0           192.168.0.59          U         1      0  ge0
  14. 192.168.0.0           192.168.0.57          U         1      0  ge0:1
  15. default              192.168.0.129         UG        1    196  
  16. 127.0.0.1            127.0.0.1            UH       101964707  lo0

  17. root@e5kd6 # traceroute 10.109.109.33
  18. traceroute: Warning: Multiple interfaces found; using 192.168.0.59 @ ge0
  19. traceroute to 10.109.109.33 (10.109.109.33), 30 hops max, 40 byte packets
  20. 1  192.168.0.2 (192.168.0.2)  1.321 ms  0.397 ms  0.365 ms
  21. 2  10.109.109.33 (10.109.109.33)  0.358 ms  0.333 ms  0.315 ms
复制代码

论坛徽章:
0
5 [报告]
发表于 2010-06-25 11:18 |只看该作者
本帖最后由 rusty_rui 于 2010-06-25 11:26 编辑

在此测试中需要用到destination 参数。

修改配置:
  1. root@e5kd6 # ifconfig ge0:1 destination 10.109.109.33
  2. root@e5kd6 # ifconfig -a
  3. lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
  4.         inet 127.0.0.1 netmask ff000000
  5. ge0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 6
  6.         inet 192.168.0.59 netmask ffffff00 broadcast 192.168.0.255
  7.         ether 8:0:20:ff:1b:5c
  8. ge0:1: flags=1000851<UP,POINTOPOINT,RUNNING,MULTICAST,IPv4> mtu 1500 index 6
  9.         inet 192.168.0.57 --> 10.109.109.33 netmask ffffff00

  10. root@e5kd6 # traceroute 10.109.109.33
  11. traceroute: Warning: Multiple interfaces found; using 192.168.0.57 @ ge0:1
  12. traceroute to 10.109.109.33 (10.109.109.33), 30 hops max, 40 byte packets
  13. 1  192.168.0.2 (192.168.0.2)  1.855 ms  0.413 ms  0.359 ms
  14. 2  10.109.109.33 (10.109.109.33)  0.352 ms  0.521 ms  0.327 ms

  15.            已经按照既定端口ge0:1 通信
  16. root@e5kd6 # netstat -rn

  17. Routing Table: IPv4
  18.   Destination           Gateway           Flags  Ref   Use   Interface
  19. -------------------- -------------------- ----- ----- ------ ---------
  20. 10.109.109.33         192.168.0.57          UH        1      1  ge0:1
  21. 192.168.00           192.168.0.57          U         1      0  ge0
  22. default              192.168.0.129         UG        1    194  
  23. 127.0.0.1            127.0.0.1            UH       101964070  lo0
复制代码

论坛徽章:
0
6 [报告]
发表于 2010-06-25 11:27 |只看该作者
自己搞个沙发坐坐。{:3_202:}{:3_202:}

论坛徽章:
1
IT运维版块每日发帖之星
日期:2016-07-29 06:20:00
7 [报告]
发表于 2010-06-25 11:34 |只看该作者
谢谢分享

论坛徽章:
221
15-16赛季CBA联赛之吉林
日期:2017-12-11 12:51:59黑曼巴
日期:2019-04-12 13:40:0515-16赛季CBA联赛之广东
日期:2019-04-23 10:41:1215-16赛季CBA联赛之辽宁
日期:2019-05-06 13:03:2815-16赛季CBA联赛之山西
日期:2019-05-09 10:56:5815-16赛季CBA联赛之青岛
日期:2019-05-17 13:57:0515-16赛季CBA联赛之新疆
日期:2019-06-10 13:39:0515-16赛季CBA联赛之天津
日期:2019-07-08 15:04:4519周年集字徽章-19
日期:2019-08-27 13:31:2619周年集字徽章-19
日期:2019-08-27 13:31:2619周年集字徽章-周
日期:2019-09-06 18:46:4715-16赛季CBA联赛之天津
日期:2019-02-27 11:24:07
8 [报告]
发表于 2010-06-25 11:45 |只看该作者
这个很不错的,顶!

论坛徽章:
1
19周年集字徽章-19
日期:2020-01-08 15:08:20
9 [报告]
发表于 2010-06-25 11:50 |只看该作者
本帖最后由 cwnlinux 于 2010-06-25 11:51 编辑

谢谢分享。非常不错。

论坛徽章:
1
19周年集字徽章-19
日期:2020-01-08 15:08:20
10 [报告]
发表于 2010-06-25 11:50 |只看该作者
谢谢楼主分享。。非常不错。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP