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流媒体服务器部署流程

《Linux流媒体服务器部署流程》文章详细介绍了流媒体服务器的部署步骤,包括更新系统、安装依赖组件、编译安装Nginx和RTMP模块、配置Nginx和FFmpeg,以及测试流媒体服务器的搭建... 目录流媒体服务器部署部署安装1.更新系统2.安装依赖组件3.解压4.编译安装(添加RTMP和openssl模块

linux下多个硬盘划分到同一挂载点问题

《linux下多个硬盘划分到同一挂载点问题》在Linux系统中,将多个硬盘划分到同一挂载点需要通过逻辑卷管理(LVM)来实现,首先,需要将物理存储设备(如硬盘分区)创建为物理卷,然后,将这些物理卷组成... 目录linux下多个硬盘划分到同一挂载点需要明确的几个概念硬盘插上默认的是非lvm总结Linux下多

linux进程D状态的解决思路分享

《linux进程D状态的解决思路分享》在Linux系统中,进程在内核模式下等待I/O完成时会进入不间断睡眠状态(D状态),这种状态下,进程无法通过普通方式被杀死,本文通过实验模拟了这种状态,并分析了如... 目录1. 问题描述2. 问题分析3. 实验模拟3.1 使用losetup创建一个卷作为pv的磁盘3.

Linux环境变量&&进程地址空间详解

《Linux环境变量&&进程地址空间详解》本文介绍了Linux环境变量、命令行参数、进程地址空间以及Linux内核进程调度队列的相关知识,环境变量是系统运行环境的参数,命令行参数用于传递给程序的参数,... 目录一、初步认识环境变量1.1常见的环境变量1.2环境变量的基本概念二、命令行参数2.1通过命令编程

Linux之进程状态&&进程优先级详解

《Linux之进程状态&&进程优先级详解》文章介绍了操作系统中进程的状态,包括运行状态、阻塞状态和挂起状态,并详细解释了Linux下进程的具体状态及其管理,此外,文章还讨论了进程的优先级、查看和修改进... 目录一、操作系统的进程状态1.1运行状态1.2阻塞状态1.3挂起二、linux下具体的状态三、进程的

Linux编译器--gcc/g++使用方式

《Linux编译器--gcc/g++使用方式》文章主要介绍了C/C++程序的编译过程,包括预编译、编译、汇编和链接四个阶段,并详细解释了每个阶段的作用和具体操作,同时,还介绍了调试和发布版本的概念... 目录一、预编译指令1.1预处理功能1.2指令1.3问题扩展二、编译(生成汇编)三、汇编(生成二进制机器语

Rsnapshot怎么用? 基于Rsync的强大Linux备份工具使用指南

《Rsnapshot怎么用?基于Rsync的强大Linux备份工具使用指南》Rsnapshot不仅可以备份本地文件,还能通过SSH备份远程文件,接下来详细介绍如何安装、配置和使用Rsnaps... Rsnapshot 是一款开源的文件系统快照工具。它结合了 Rsync 和 SSH 的能力,可以帮助你在 li

Linux部署jar包过程

《Linux部署jar包过程》文章介绍了在Linux系统上部署Java(jar)包时需要注意的几个关键点,包括统一JDK版本、添加打包插件、修改数据库密码以及正确执行jar包的方法... 目录linux部署jar包1.统一jdk版本2.打包插件依赖3.修改密码4.执行jar包总结Linux部署jar包部署

mysqld_multi在Linux服务器上运行多个MySQL实例

《mysqld_multi在Linux服务器上运行多个MySQL实例》在Linux系统上使用mysqld_multi来启动和管理多个MySQL实例是一种常见的做法,这种方式允许你在同一台机器上运行多个... 目录1. 安装mysql2. 配置文件示例配置文件3. 创建数据目录4. 启动和管理实例启动所有实例

Linux内存泄露的原因排查和解决方案(内存管理方法)

《Linux内存泄露的原因排查和解决方案(内存管理方法)》文章主要介绍了运维团队在Linux处理LB服务内存暴涨、内存报警问题的过程,从发现问题、排查原因到制定解决方案,并从中学习了Linux内存管理... 目录一、问题二、排查过程三、解决方案四、内存管理方法1)linux内存寻址2)Linux分页机制3)