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脚本(shell)的使用方式

《Linux脚本(shell)的使用方式》:本文主要介绍Linux脚本(shell)的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录概述语法详解数学运算表达式Shell变量变量分类环境变量Shell内部变量自定义变量:定义、赋值自定义变量:引用、修改、删

Linux链表操作方式

《Linux链表操作方式》:本文主要介绍Linux链表操作方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、链表基础概念与内核链表优势二、内核链表结构与宏解析三、内核链表的优点四、用户态链表示例五、双向循环链表在内核中的实现优势六、典型应用场景七、调试技巧与

详解Linux中常见环境变量的特点与设置

《详解Linux中常见环境变量的特点与设置》环境变量是操作系统和用户设置的一些动态键值对,为运行的程序提供配置信息,理解环境变量对于系统管理、软件开发都很重要,下面小编就为大家详细介绍一下吧... 目录前言一、环境变量的概念二、常见的环境变量三、环境变量特点及其相关指令3.1 环境变量的全局性3.2、环境变

Linux系统中的firewall-offline-cmd详解(收藏版)

《Linux系统中的firewall-offline-cmd详解(收藏版)》firewall-offline-cmd是firewalld的一个命令行工具,专门设计用于在没有运行firewalld服务的... 目录主要用途基本语法选项1. 状态管理2. 区域管理3. 服务管理4. 端口管理5. ICMP 阻断

Linux实现线程同步的多种方式汇总

《Linux实现线程同步的多种方式汇总》本文详细介绍了Linux下线程同步的多种方法,包括互斥锁、自旋锁、信号量以及它们的使用示例,通过这些同步机制,可以解决线程安全问题,防止资源竞争导致的错误,示例... 目录什么是线程同步?一、互斥锁(单人洗手间规则)适用场景:特点:二、条件变量(咖啡厅取餐系统)工作流

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存

Linux使用scp进行远程目录文件复制的详细步骤和示例

《Linux使用scp进行远程目录文件复制的详细步骤和示例》在Linux系统中,scp(安全复制协议)是一个使用SSH(安全外壳协议)进行文件和目录安全传输的命令,它允许在远程主机之间复制文件和目录,... 目录1. 什么是scp?2. 语法3. 示例示例 1: 复制本地目录到远程主机示例 2: 复制远程主

Linux基础命令@grep、wc、管道符的使用详解

《Linux基础命令@grep、wc、管道符的使用详解》:本文主要介绍Linux基础命令@grep、wc、管道符的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录grep概念语法作用演示一演示二演示三,带选项 -nwc概念语法作用wc,不带选项-c,统计字节数-

Linux CPU飙升排查五步法解读

《LinuxCPU飙升排查五步法解读》:本文主要介绍LinuxCPU飙升排查五步法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录排查思路-五步法1. top命令定位应用进程pid2.php top-Hp[pid]定位应用进程对应的线程tid3. printf"%

Linux下安装Anaconda3全过程

《Linux下安装Anaconda3全过程》:本文主要介绍Linux下安装Anaconda3全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录简介环境下载安装一、找到下载好的文件名为Anaconda3-2018.12-linux-x86_64的安装包二、或者通