# [SOLVED] making laptop with adhoc + nat + dhcp

## theluckymike

Hi there. 

All day I was trying to set up my wifi card as ad hoc network were I can connect with my other laptop as I don't have any router n stuff..

My eth0 ( WAN ) must be dhcp cos my ISP is giving me random ip. And my wlan0 should be in ad-hoc mode with nat and dhcp server on it..

I have managed it to be in adhoc mode, but that is best I can do. When Im trying to connect to it with laptop it's just not giving IP address..  

As I just started unix and gentoo life, i'm not sure what exact information I should give - so if you need something, please ask..

Any hints and ideas would be nice.

Thanks in advice, 

MikeLast edited by theluckymike on Sat May 26, 2012 8:54 am; edited 3 times in total

----------

## NeddySeagoon

theluckymike,

Welcome to Gentoo.

For ad-hoc mode, all the systems involved used self assigned link local IP addresses.  There is no NAt and no dhcp server.

Your dhcpcd (or whatever you use) needs to support this.

Normally you set the zeroconf USE flag on in make.menuconfig.

You can also assign static IP addresses to all the members of the ad hoc network, if you prefer.

The must all be unique and they must all be in the same subnet.

Link local addresses begin 169.254.

----------

## theluckymike

Thank you for answer.

But then it should be easy to set up adhoc network. At least in windows xp and ubuntu it took for me 3 minutes.. Here - it's already 3 days :D 

Were could be problem, that if I make adhoc network ture nmapplet and noboady can't connect without configuring addresses. That would be the best, or even only option for me - because I really don't want to configure my mobile and another laptop everytime when I am at home or away again..

I am familiar with routing and IP addresses, local network n stuff, I just don't ged it why I cannot get IP automaticly. I was in irc channel before and everybody sad to install dhcpd for that..

----------

## NeddySeagoon

theluckymike,

dhcpd is a server to provide networking setups to other systems. That not what you need.

ad hoc networking has to work without and dhcp server, no gateway and so on.

The systems in the ad hoc network can only communicate amount themselves. 

In Gentoo you need dhcpcd built with USE zeroconf

That use flag is essential to get a link local IP address when a dhcp server cannot be contacted.

If your ad hoc network will use encryotion, you need wpa_supplicant or possibly wireless-tools to set up the encryption.

What do you have in your /etc/conf.d/net file  ?

What does  emerge -iinfo show?

----------

## theluckymike

/etc.conf.d/net

```
#Generated by NetworkManager

###### Global Configuration ######

modules="wpa_supplicant"

###### Connection Configuration ######

#----------------------------------

auto_bumcibum="true"

config_bumcibum=( "dhcp" )

enable_ipv6_bumcibum="false"

#----------------------------------

mac_eth0="00:18:39:D4:1E:E2"

auto_eth0="true"

enable_ipv6_eth0="false"

```

this was my try to make bumcibum network true nm-applet.. 

I cannot do nothing with emerge, because i'm using it now. That will be my next post - why firefox was emerging 3,5h and openoffice 20h X_X

----------

## NeddySeagoon

theluckymike,

Its quite safe to run 

```
emerge --info
```

 at any time.  It does not install anything, rather it prints information about your system.

```
config_bumcibum=( "dhcp" ) 
```

Id correct for the old baselayout1

For baselayout2, you should not have the two "()" but thats tolerated meanwhile.

Using dhcp is correct too - but only if its built with zeroconfig.

Openoffice?  Thats dead now - Oracle pretty much killed it when they took over Sun. libreoffice is the live fork. Its the biggest package in Gentoo, so it takes a long time to built

Firefox is also big.

If you do not want to build them yourself, Gentoo provides pre built binaries for these packages and a few others. firefox-bin and libreoffice-bin will be these two.

----------

## theluckymike

emerge --info 

```

Portage 2.1.10.49 (default/linux/x86/10.0/desktop, gcc-4.5.3, glibc-2.14.1-r3, 3.2.12-gentoo i686)

=================================================================

System uname: Linux-3.2.12-gentoo-i686-AMD_Athlon-tm-_XP_Processor_3000+-with-gentoo-2.0.3

Timestamp of tree: Thu, 17 May 2012 15:45:01 +0000

app-shells/bash:          4.2_p20

dev-lang/python:          2.7.3-r1, 3.2.3

dev-util/cmake:           2.8.7-r5

dev-util/pkgconfig:       0.26

sys-apps/baselayout:      2.0.3

sys-apps/openrc:          0.9.8.4

sys-apps/sandbox:         2.5

sys-devel/autoconf:       2.13, 2.68

sys-devel/automake:       1.11.1

sys-devel/binutils:       2.21.1-r1

sys-devel/gcc:            4.5.3-r2

sys-devel/gcc-config:     1.5-r2

sys-devel/libtool:        2.4-r1

sys-devel/make:           3.82-r1

sys-kernel/linux-headers: 3.1 (virtual/os-headers)

sys-libs/glibc:           2.14.1-r3

Repositories: gentoo

ACCEPT_KEYWORDS="x86"

ACCEPT_LICENSE="* -@EULA"

CBUILD="i686-pc-linux-gnu"

CFLAGS="-O2 -march=i686 -pipe"

CHOST="i686-pc-linux-gnu"

CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt"

CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/sandbox.d /etc/terminfo"

CXXFLAGS="-O2 -march=i686 -pipe"

DISTDIR="/usr/portage/distfiles"

FEATURES="assume-digests binpkg-logs distlocks ebuild-locks fixlafiles news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"

FFLAGS=""

GENTOO_MIRRORS="http://gentoo.supp.name/ http://ftp.fi.muni.cz/pub/linux/gentoo/ http://gentoo.mirror.dkm.cz/pub/gentoo/ http://gentoo.mirror.web4u.cz/"

LDFLAGS="-Wl,-O1 -Wl,--as-needed"

MAKEOPTS="-j2"

PKGDIR="/usr/portage/packages"

PORTAGE_CONFIGROOT="/"

PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"

PORTAGE_TMPDIR="/var/tmp"

PORTDIR="/usr/portage"

PORTDIR_OVERLAY=""

SYNC="rsync://rsync.cz.gentoo.org/gentoo-portage"

USE="X a52 aac acl acpi alsa berkdb bluetooth branding bzip2 cairo cdda cdr cli consolekit cracklib crypt cups cxx dbus dri dts dvd dvdr emboss encode exif fam firefox flac fortran gdbm gif gpm gtk iconv introspection jpeg lcms ldap libnotify lock mad midi mng modules mp3 mp4 mpeg mudflap ncurses nls nptl ogg opengl openmp pam pango pcre pdf png polickykit policykit ppds pppd qt3support readline sdl session spell ssl startup-notification svg tcpd thunar tiff truetype udev udisks unicode upower usb vorbis wxwidgets x264 x86 xcb xml xorg xulrunner xv xvid zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="evdev synaptics" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" PHP_TARGETS="php5-3" PYTHON_TARGETS="python3_2 python2_7" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="nouveau" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"

Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LANG, LC_ALL, LINGUAS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON

```

I failed with idea about finding some net.conf on ubuntu ( my wifes laptop :D ) were adhoc works perfect.. looks like ubuntu is  not so .conf system, but saves files in different way..

anyway - can someone show me some  etc/init.d/net config with example of working adhoc with wep at least. If I understood right, that it stores config there.. ?

----------

## NeddySeagoon

theluckymike,

You have built your system without support for assigning link local IP addresses.

Your USE flags are 

```
USE="X a52 aac acl acpi alsa berkdb bluetooth branding bzip2 cairo cdda cdr cli consolekit cracklib crypt cups cxx dbus dri dts dvd dvdr emboss encode exif fam firefox flac fortran gdbm gif gpm gtk iconv introspection jpeg lcms ldap libnotify lock mad midi mng modules mp3 mp4 mpeg mudflap ncurses nls nptl ogg opengl openmp pam pango pcre pdf png polickykit policykit ppds pppd qt3support readline sdl session spell ssl startup-notification svg tcpd thunar tiff truetype udev udisks unicode upower usb vorbis wxwidgets x264 x86 xcb xml xorg xulrunner xv xvid zlib"
```

That includes the flags set in your profile and in /etc/make.conf

Notice that 

```
zeroconf
```

is missing from your USE flags.

Edit /etc/make.conf and add zeroconf to your USE flag settings. Now

```
 emerge -uDNav world
```

to rebuild the affected packages so zeroconf takes effect.

At your next reboot, ad hoc networking should work as dhcpcd will now assign a link local IP address instead of nothing when a dhcp server canot be found.

----------

## theluckymike

NeddySeagoon, thank you very much :)

I will try this emediatly whem system will be emerged. I it doing it already at least 20h+ and i'm really tired of waiting.. I do not want to use bin packages - that's why I think I like gentoo - u can do everything special - special for my pc. So I really hope there will be at least 2% diference between emeging firefox and liberoficce than isntalling bin packages :)

Il post my results as soon emerging will be over.

EDITED:

Neddy - you made my day. :)

This is 3rd time for me trying gentoo. First 2 times few years ago I did quite a lot mistakes and got tired of searching every single time. Looks like with years come experience, and now only few things is missing, but I really want to get rid of Mircosoft world.. :) 

 Thank you ;) cheers

----------

## theluckymike

Huh

Looks like my fun was too short :) 

Everything was fine till system reboot. I turned pc off for night and this morning now it don't connect to wifi anymore. Problem description - my pc is all the time trying to connect to adhoc. So wile it will not connect by it self I will not be able to connect to adhoc with another devices. 

What kind of troubleshooting I should do?

----------

## NeddySeagoon

theluckymike,

The connection sequence for wifi is:-

Associate with the access point if one can be found.

Apply for an IP address with dhcpcd.  If that fails, self allocate a link local IP address, so ad hoc should work. 

Read

```
less /usr/share/doc/openrc-0.9.9.3/net.example.bz2
```

to see what to do with wifi setups.

Put your version of openrc in the path.

----------

## theluckymike

Hi.

I kinda tried to do the best and the ad-hoc was working again and it was fine. Now after reboot my laptop again can't to put up ad-hoc. Settings didn't change. Just can't understand why it is like that..

some info:

https://gist.github.com/2790395

and dmesg shows all the time:

```

1347.156992] wlan0: Trigger new scan to find an IBSS to join

[ 1350.036585] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1351.166368] wlan0: Trigger new scan to find an IBSS to join

[ 1354.033456] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1355.167609] wlan0: Trigger new scan to find an IBSS to join

[ 1358.041388] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1359.226216] wlan0: Trigger new scan to find an IBSS to join

[ 1362.046792] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1363.169690] wlan0: Trigger new scan to find an IBSS to join

[ 1366.023212] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1367.150688] wlan0: Trigger new scan to find an IBSS to join

[ 1370.031211] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1371.164587] wlan0: Trigger new scan to find an IBSS to join

[ 1374.028956] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1375.160494] wlan0: Trigger new scan to find an IBSS to join

[ 1378.022919] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1379.146051] wlan0: Trigger new scan to find an IBSS to join

[ 1382.022257] wlan0: Selected IBSS BSSID be:12:d1:b3:25:34 based on configured SSID

[ 1383.146880] wlan0: Trigger new scan to find an IBSS to join

```

EDIT:

fml. I didn't know that my system ( have no idea why ) can't tell AP security by default. I had 128bit security but by default it was connecting to 64bit. Now it looks fine. There should be at least error, that something is wrong, not just trying to connect all the time.

Anyway - thank you for your time :)

----------

