|
#1
|
|||
|
|||
|
Bhe, per una volta non faccio un post di richiesta ma per dare ai posteri qualcosa di utile. Supponiamo di avere un portatile, e di andare in giro collegandosi via dhcp in alcune reti e con ip statico in una (e si, ora non esageriamo, una penso che basti). oppure si vuole semplicemente avere un ip fisso quando non si è collegati ad una rete. dopo varie peripezie e con l'uso di dhcping ho creato questo file (che poi mostrerò dove richiamare): kbyte@kbytelnx:~$ cat /etc/network/netselect #!/bin/sh ifconfig eth0 0 up > /dev/null 2> /dev/null route add default dev eth0 netmask 0.0.0.0 > /dev/null 2> /dev/null RETVAL=`/usr/sbin/dhcping -s 255.255.255.255 2>/dev/null | grep \ "Got answer from:" -c` ifconfig eth0 down > /dev/null 2> /dev/null if [ $RETVAL -eq 0 ]; then echo "eth0-static" else echo "eth0-dynamic" fi Bene, ora per capire come il tutto funziona basta vedere il canonico /etc/network/interfaces limitandoci alla sezione di solo eth0: auto eth0 mapping eth0 script /etc/network/netselect map eth0-dynamic map eth0-static iface eth0-static inet static address 10.0.0.2 netmask 255.255.255.0 network 10.0.0.0 broadcast 10.0.0.255 gateway 10.0.0.1 mtu 1452 iface eth0-dynamic inet dhcp Fatto ciò il gioco è fatto, basta riavviare o fare il semplice /etc/init.d/network restart ![]() -- | / | \Byte - Andrea Briganti - kbytesys(aaattt)tiscali.it CSLug member: http://cslug.linux.it - JID: kbyte@jabber.linux.it ***Se la risposta è Bush, la domanda doveva essere proprio stupida! |
|
#2
|
|||
|
|||
|
On Fri, 24 Oct 2003 17:01:04 GMT, Kbyte wrote:
> Fatto ciò il gioco è fatto, basta riavviare o fare il semplice > /etc/init.d/network restart ![]() ....Oppure usare uno a caso dei tool gia` esistenti, che hanno qualche beneficio aggiuntivo (lanciare degli script a seconda del contesto)...: mizio@gate:~$ apt-cache search auto IP config laptop divine - Automatic IP configuration detection for laptops guessnet - Guess what network is connected to an ethernet device intuitively - Automatic IP configuration detection for laptops laptop-net - Automatically adapt laptop ethernet laptop-netconf - network detection and configuration program for laptops whereami - Automatically reconfigure your (laptop) system for a new location Io, in particolare uso divine proficuamente. ![]() -- Maurizio - Tannoiser - Lemmo Founder Member of ERLUG http://erlug.linux.it ------------------------------------------------------------------------------- A bleeding heart can be hell on the carpeting. |
| Thread Tools | |
| Display Modes | |
|