Wireless Ad-Hoc Network – Linux

2024-02-04 10:58
文章标签 linux ad network hoc wireless

本文主要是介绍Wireless Ad-Hoc Network – Linux,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转自

 

http://mohan43u.wordpress.com/2010/01/31/wireless-ad-hoc-network-linux/

 

 

Long time back, I actually did peer-to-peer with RJ232 connector using mine and my friend’s laptops. Its really simple and straight forward. Choose a local subnet( probably 192.168.2.0/24), assign 192.168.2.1 to one machine and assign 192.168.2.2 to another machine. Thats all, connection established and I used ‘nc’ to transfer files.

This time, its the same old thing, but without RJ232 wire. Also I just configured my system as a gateway so that my friend can access Internet through my laptop.

Before starting, I conformed that my wireless is working,

$ su -c'iwconfig'
lo        no wireless extensions.
eth1      no wireless extensions.
eth3      IEEE 802.11bg  ESSID:""
Mode:Managed  Frequency:2.412 GHz  Access Point: Not-Associated
Bit Rate:54 Mb/s   Tx-Power:off
Retry min limit:7   RTS thr:off   Fragment thr:off
Power Managementmode:All packets received
Link Quality=5/5  Signal level=0 dBm  Noise level=0 dBm
Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
Tx excessive retries:0  Invalid misc:0   Missed beacon:0
pan0      no wireless extensions.
eth0      no wireless extensions.

First I announced a Wireless Ad-Hoc with a good name(ESSID “Dark”), here, there is something called WEP, but I’m still not able to set WEP passphrase through iwconfig. If someone had success through ‘iwconfig’ please help me to learn. The below ad-hoc network will not use WEP or any authentication.

$ su -c'iwconfig eth3 essid "Dark" mode ad-hoc channel 1'

waited for 2 – 10 seconds, and then tried to connect to that “Dark” network.

$ su -c'iwconfig eth3 essid "Dark" mode ad-hoc channel 1'

I tried the above command more than one time till I’m associated with a Cell. If you get a mac address in ‘Cell’, it means you are now connected to the ‘Dark’ Network.

$ su -c'iwconfig eth3'
eth3      IEEE 802.11bg  ESSID:"Dark"
Mode:Ad-Hoc  Frequency:2.412 GHz  Cell: F6:A5:B9:E6:37:E3
Bit Rate=54 Mb/s   Tx-Power:32 dBm
Retry min limit:7   RTS thr:off   Fragment thr:off
Power Managementmode:All packets received
Link Quality=5/5  Signal level=-57 dBm  Noise level=-96 dBm
Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
Tx excessive retries:0  Invalid misc:0   Missed beacon:0

Now, my link-layer is configured, next is to configure the ip layer,

$ su -c'ifconfig eth3 192.168.2.1 netmask 255.255.255.0'
$ su -c'ifconfig eth3; route'
eth3      Link encap:Ethernet  HWaddr 00:1a:73:9f:d3:47
inet addr:192.168.2.1  Bcast:192.168.2.255  Mask:255.255.255.0
inet6 addr: fe80::21a:73ff:fe9f:d347/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:2
TX packets:0 errors:6 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
Interrupt:19 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     *               255.255.255.0   U     0      0        0 eth3
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     1000   0        0 eth0
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0

Now I configured IP layer, the next part is to configure my debian to route packets,

$ su -c'sysctl -w net.ipv4.ip_forward=1'
$ su -c'iptables --verbose --table filter --policy FORWARD ACCEPT'
$ su -c'iptables --verbose --table nat --append POSTROUTING --jump MASQUERADE'

Note, that the above steps are just for current running kernel, if I want my changes to be permanent, I need to edit /etc/sysctl.conf and I need to save my current iptables using ‘iptables-save/iptables-restore’.

Thats all from the gateway machine(that is, my laptop), now I need to add my friend’s laptop to this ‘Dark’ Network.

$ sudo iwconfig wlan0 essid "Dark" mode ad-hoc channel 1
$ sudo ifconfig wlan0 192.168.2.2 netmask 255.255.255.0
$ sudo route add default gw 192.168.2.1
$ sudo echo "nameserver 192.168.1.1" >> /etc/resulv.conf

Thats all from my friend’s machine, now he just opened firefox and happily browsed from the balcony. No more wires.

Whenever my friends come to my room, they have some bit of tough time accessing internet, becuase most of the time, my laptop will be connected with internet through ADSL. Obviously they have shyness to ask me for stop my surfing. But now, I can happily share my internet connection with my friends. I don’t need to buy a wireless router. My laptop itself with the ADSL router doing what a wireless router can do.

Thanks linux.

这篇关于Wireless Ad-Hoc Network – Linux的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/677252

相关文章

Linux之systemV共享内存方式

《Linux之systemV共享内存方式》:本文主要介绍Linux之systemV共享内存方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、工作原理二、系统调用接口1、申请共享内存(一)key的获取(二)共享内存的申请2、将共享内存段连接到进程地址空间3、将

快速修复一个Panic的Linux内核的技巧

《快速修复一个Panic的Linux内核的技巧》Linux系统中运行了不当的mkinitcpio操作导致内核文件不能正常工作,重启的时候,内核启动中止于Panic状态,该怎么解决这个问题呢?下面我们就... 感谢China编程(www.chinasem.cn)网友 鸢一雨音 的投稿写这篇文章是有原因的。为了配置完

Linux命令之firewalld的用法

《Linux命令之firewalld的用法》:本文主要介绍Linux命令之firewalld的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux命令之firewalld1、程序包2、启动firewalld3、配置文件4、firewalld规则定义的九大

Linux之计划任务和调度命令at/cron详解

《Linux之计划任务和调度命令at/cron详解》:本文主要介绍Linux之计划任务和调度命令at/cron的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux计划任务和调度命令at/cron一、计划任务二、命令{at}介绍三、命令语法及功能 :at

Linux下如何使用C++获取硬件信息

《Linux下如何使用C++获取硬件信息》这篇文章主要为大家详细介绍了如何使用C++实现获取CPU,主板,磁盘,BIOS信息等硬件信息,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录方法获取CPU信息:读取"/proc/cpuinfo"文件获取磁盘信息:读取"/proc/diskstats"文

Linux内核参数配置与验证详细指南

《Linux内核参数配置与验证详细指南》在Linux系统运维和性能优化中,内核参数(sysctl)的配置至关重要,本文主要来聊聊如何配置与验证这些Linux内核参数,希望对大家有一定的帮助... 目录1. 引言2. 内核参数的作用3. 如何设置内核参数3.1 临时设置(重启失效)3.2 永久设置(重启仍生效

kali linux 无法登录root的问题及解决方法

《kalilinux无法登录root的问题及解决方法》:本文主要介绍kalilinux无法登录root的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,... 目录kali linux 无法登录root1、问题描述1.1、本地登录root1.2、ssh远程登录root2、

Linux ls命令操作详解

《Linuxls命令操作详解》通过ls命令,我们可以查看指定目录下的文件和子目录,并结合不同的选项获取详细的文件信息,如权限、大小、修改时间等,:本文主要介绍Linuxls命令详解,需要的朋友可... 目录1. 命令简介2. 命令的基本语法和用法2.1 语法格式2.2 使用示例2.2.1 列出当前目录下的文

Linux中的计划任务(crontab)使用方式

《Linux中的计划任务(crontab)使用方式》:本文主要介绍Linux中的计划任务(crontab)使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、前言1、linux的起源与发展2、什么是计划任务(crontab)二、crontab基础1、cro

Linux换行符的使用方法详解

《Linux换行符的使用方法详解》本文介绍了Linux中常用的换行符LF及其在文件中的表示,展示了如何使用sed命令替换换行符,并列举了与换行符处理相关的Linux命令,通过代码讲解的非常详细,需要的... 目录简介检测文件中的换行符使用 cat -A 查看换行符使用 od -c 检查字符换行符格式转换将