Koozali.org: home of the SME Server

I have a network with two access ports

Offline mgb

  • ****
  • 558
  • +0/-0
I have a network with two access ports
« on: December 31, 2014, 12:10:50 PM »
Hello Question
 I have a network with two access ports
 Is there software that can change.
 If one network disconnected then it transfers
 The second port network.
 Thank you.

 
« Last Edit: December 31, 2014, 12:19:45 PM by mgb »
Thanks all for helping
Skype yosii2009

Offline mmccarn

  • *
  • 2,627
  • +10/-0
Re: I have a network with two access ports
« Reply #1 on: December 31, 2014, 02:24:31 PM »
The usual recommendation for this configuration is to install a dual-wan router on the network that provides auto failover (that is, replace your switch and two routers with one device like the Netgear FVS336Gv2 or the Cisco RV320

You could write a script that pings an internet host and swaps the gatewayip if the ping fails - I doubt that you'll find any existing WAN fail-over code for Centos that can be used safely on a SME server.

Here is some pseudocode that would do what you want - once you have the script written and tested you'd also want to configure it as a supervised service so it was always running:

Code: [Select]
while true
  if (ping 4.2.2.1) && (ping 8.8.8.8)
    sleep 30
  else
    if $(config get GatewayIP) eq 10.0.0.254
      config set GatewayIP 10.0.0.253
      signal-event remoteaccess-update
    else
      config set GatewayIP 10.0.0.254
      signal-event remoteaccess-update
    endif
  endif
endwhile

Offline mgb

  • ****
  • 558
  • +0/-0
Re: I have a network with two access ports
« Reply #2 on: January 01, 2015, 08:06:07 AM »
/wgw: line 4: syntax error near unexpected token `else'
./wgw: line 4: `  else'
Thanks all for helping
Skype yosii2009

Offline mmccarn

  • *
  • 2,627
  • +10/-0
Re: I have a network with two access ports
« Reply #3 on: January 01, 2015, 04:53:25 PM »
Sorry...
...
Here is some pseudocode...

That's just an outline showing the logic you could use to create a script to do what you want.

Problems I know about:
- I don't know if bash has a "while" loop
-  I doubt that the ping commands I gave would work as written (you'd at least need an argument to limit the number of ping requests that get sent)
- the bash 'if', 'else', 'endif' structure does not work as I have shown it (so all if/else/endif structures need rewriting)

Things that I know would work:
sleep 30 (do nothing for 30 seconds)
$(config getprop GatewayIP) (returns the current value of GatewayIP -- test using echo $(config get GatewayIP))
config set GatewayIP 10.0.0.253; signal-event remoteaccess-update (should work; you should test this manually before sitting down to write and debug the rest of the script)

There is lots of actual coding you still need to do.

For example, after googling 'bash if' and reading the results, I can verify that this command successfully compares my current gateway and returns 'yes' for a match and 'no' for a non-match.  Replace '192.168.200.1' with your gateway, then expand the 'echo yes' and 'echo no' commands to do what you want depending on if the gateway matches.
Code: [Select]
if [ $(config get GatewayIP) = 192.168.200.1 ];then echo yes; else echo no; fi

Offline mgb

  • ****
  • 558
  • +0/-0
Re: I have a network with two access ports
« Reply #4 on: January 04, 2015, 03:52:51 PM »
  ping 192.168.183.1  -c 3 >/dev/null 2>&1
        if [ $? -ne 0 ]
        then
            echo "192.168.183.1 dhcp1 is down"
cp -a /root/dhcpd.conf  /dhcp/dhcpd.conf
service  /etc/rc.d/init.d/dhcpd restart



 # service network stop

 # /sbin/ip route add default via 192.168.183.1

# ip route add 192.168.183.1 dev eth2

# service  network restart

 

        else

            echo "192.168.0.1dhcp2 is up"

        fi
        exit 0
is ok  config dhcpd.conf   
Thanks all for helping
Skype yosii2009

Offline ReetP

  • *
  • 3,732
  • +5/-0
Re: I have a network with two access ports
« Reply #5 on: January 05, 2015, 11:50:41 AM »

cp -a /root/dhcpd.conf  /dhcp/dhcpd.conf
service  /etc/rc.d/init.d/dhcpd restart

is ok  config dhcpd.conf   

No !

DON'T use :

Code: [Select]
cp dhcpd.conf
This file, and many others, are generated automatically by the system. If you manually change them the changes can easily be lost if there are other changes on your server.

You really need to use the proper commands to do this sort of thing as has been suggested.

You are better to use the format suggested above :

Code: [Select]
config set GatewayIP 10.0.0.253; signal-event remoteaccess-update(note this is not what you require, but gives the format using a CLI command)

You may find that something like "signal-event ip-change" is a better command to use.

However, you probably need to set other properties as well before doing this - have a look at these :

config show InternalInterface
config show ExternalInterface
config show ExternalNetmask
config show GatewayIP
config show LocalIP
config show LocalNetmask

Or to see them all try :

Code: [Select]
config show |less
You may need something like :

Code: [Select]
config set GatewayIP 10.0.0.253
config setprop ExternalInterface Name eth2 IPAddress x.x.x.x etc
signal-event ip-change

NB - this is JUST an example. you really need to read and understand the systems and the code first.

Have a look at some of this for more ideas :

http://wiki.contribs.org/Useful_Commands
http://wiki.contribs.org/DB_Variables_Configuration

B. Rgds
John
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline mgb

  • ****
  • 558
  • +0/-0
Re: I have a network with two access ports
« Reply #6 on: January 05, 2015, 01:11:54 PM »
Right you're right.
Due to a serious change
 So I prefer to do only the dhcpd.conf
 I define an external DNS
 And the exchange Then it's just for a limited time - to fix the problem
 Then I will return the impulse DHCP
 It is clear that the server will not be able to browse the web
Thanks all for helping
Skype yosii2009

Offline mgb

  • ****
  • 558
  • +0/-0
Re: I have a network with two access ports
« Reply #7 on: January 09, 2015, 09:34:31 AM »
   ping walla.com  -c 3 >/dev/null 2>&1
        if [ $? -ne 0 ]
        then
            echo "wlan0 is down"
service network  stop
cp  /etc/sysconfig/network183 /etc/sysconfig/network
 service network   start
sleep 3




# cp  /root/messaping1.txt
        else
            echo "wlan0 is up"
service network  stop

 cp  /etc/sysconfig/network01  /etc/sysconfig/network

 service network   start


sleep 3


      fi
        exit 0

Thanks all for helping
Skype yosii2009