LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-31-2015, 11:15 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Rep: Reputation: 32
Question socket problem behind NAT


Hello,

I would like to connect to computers using sockets, but between both, there is a NAT.
If a connect directly both computers, the connection is ok. If any computer shutdown and power on again, re-connection is successful.

But with NAT, if some computer go down and restart again, some times, computer can not connect with computer behind NAT.

I see socket options like keep alive but I am not sure how to use.

Any advice?
 
Old 01-31-2015, 12:06 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
It is a firewall-configuration problem, google for port-forwarding.
http://portforward.com/english/routers/port_forwarding/
 
Old 01-31-2015, 04:54 PM   #3
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Original Poster
Rep: Reputation: 32
Hello,

It is not a port-forwaring problem.

Internal PC has 192.168.1.x and external PC has 192.168.5.100 (WAN port has 192.168.5.32).
In NAT Table I have create de follow rule:

external ip external port internal ip internal port
192.168.5.32 8888 192.168.1.20 8888

Now, external PC try to connect with internal PC, then router detect that somebody try to connect using port 8888, and forwaring this connection as rule describe before.


Now, I shutdown internal PC but external PC tell that connection is still alive and no drop it.
If I turn on internal PC, external PC can not reconnect with internal PC because old socket is still alive.

Is there any way to detect if socket is correct?
If a detect that socket is wrong, perhaps I could drop old connection and the try to reconnect.
 
Old 01-31-2015, 06:59 PM   #4
genss
Member
 
Registered: Nov 2013
Posts: 741

Rep: Reputation: Disabled
Quote:
Originally Posted by webquinty View Post
Is there any way to detect if socket is correct?
If a detect that socket is wrong, perhaps I could drop old connection and the try to reconnect.
implement heartbleed ? (or just ping-pong msgs)
 
Old 02-01-2015, 12:04 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
If you want to use TCP.KEEPALIVE then use setsockopt(SOL_SOCKET,SO_KEEPALIVE)
 
  


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
NAT and NAT Server behind its own NAT(private network) zeusys Linux - Networking 1 06-08-2011 06:22 PM
Can I use NAT and some local hosts without NAT on linux box? tkmbe Linux - Networking 1 08-12-2010 02:38 PM
NAT Problem ajkannan83 Linux - Networking 2 08-05-2010 09:40 AM
a problem about NAT wangqian Linux - Networking 2 04-15-2006 03:38 AM
Susefirewall2 Nat Problem / nat 1:1 trubi Linux - Distributions 0 07-20-2004 05:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:02 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