LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-14-2015, 05:38 PM   #1
M0nteZ
LQ Newbie
 
Registered: Feb 2015
Posts: 6

Rep: Reputation: Disabled
Debian - set default gateway from script or ??


Hello everyone,
I like to find my answers by reading rather than posting.
But this time i have no clues on solving this issue i have.

It's a mini pc with debian arm7 install and Huaweiy MU609 modem in a PCI-e slot.
so just a basic linux pc with GSM modem right.
Well this one has a TCP stack as well, so i am connecting to data provider and geting the IP address on a eth1.
eth0 is LAN for troubleshoting.
Problem is setting the gateay to be on GSM modem eth1 interface.
The pc always puts the gateway to be on address for the LAN after reboot.
I can not disable LAN cause i need it for troubleshoting.

I made a script to delete default gw after boot, but to add current one is another story.
when connecting to GSM provider i get a diffferent IP and gateway every time, so ...

how do i set the gateway dinamically and be sure i'll have internet access ??

this gives me a gateway ip:
ip addr show eth1 | grep inetb | awk '{print }' | cut -d/ -f1

but how do i enter it in the
ip route add default via xxx.xxx.xxx.xxx

ip route expects to se numbers only there. I tried with variables from a script
bu no go.

on red hat there is a GATEWAYDEV=ethX command, which does not exist in Debian.

ANy help greatly appreciated.
Thank You
 
Old 02-21-2015, 07:27 AM   #2
M0nteZ
LQ Newbie
 
Registered: Feb 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
I have solved the problem , so if anyone is interested this is what helped me.

have about 200 units connecting to GSM into a M2M type of network.
Provider does not have a gateway address to give me that i can enter for GSM interface. So units connect but I can not get to them with ssh.
Since there is also a LAN (eth0) connection PC would auto set gateway to the eth0
which is wrong.
Problem was to set the default gateway to be the IP address which is given by M2M.
And on 200 units every one has its own static IP address based on installed SIM.
I am using this to get the IP address of the interface when connected:
hostname -I | cut -f2 -d' '
f2 gives me the second ethernet connection which is the one on eth1 (f1 is eth0)

Then it's easy, put in rc.local
ip route del default
ip route add default via `hostname -I | cut -f2 -d' '`

Tricky part was to find right comma mark before hostname and at the end of same line after ...-d ' '.
I think the tik is called U+FE11, looks like a back-slash.

Now every units that connects gets the ip and puts it in the gateway, so I'm able to
connect to the units via ssh.

Maybe it will help someone else as well.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
confused about if default gateway is set right obiwannabe Linux - Networking 5 06-23-2013 07:40 AM
Default gateway not being set when using DHCP ret602 Linux - Networking 1 09-20-2007 12:17 PM
How to set default gateway Harlin Linux - Networking 2 02-28-2006 03:17 AM
How can I tell what my default gateway is currently set as? abefroman Linux - Networking 6 09-10-2005 12:15 PM
how do I add script to set default gateway on boot for eth1 abg Linux - Networking 3 10-01-2003 05:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 07:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration