DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003

    ServerSocket / linux iptables problem

    Hello all,

    I am attempting to construct a firewall/packet filtering system under linux, and need it to recognise connections to a ServerSocket on a specified port. However, new ServerSockets are not assigned to a specific IP address, as they are always at a port on the local host. Linux iptables will not recognise the request however as there is no IP address.

    So I was wondering......

    Is there any way of creating a ServerSocket with an IP address?


  2. #2
    Join Date
    Nov 2003

    Sorry I just found the constructor that allows you to specify an IP address.

    This is now linux iptables-specific and I apologise, but if anyone can help it would be much appreciated!

    Please move to a more relevant forum if needed.

    I have set up iptables to accept inputs to the localhost for packets to/from port 200 by:

    iptables -A INPUT -d localhost -p tcp --dport 200 -j ACCEPT
    iptables -A INPUT -d localhost -p tcp --sport 200 -j ACCEPT

    the default policy is set to DROP.

    My Java application attempts to create a new ServerSocket on port 200 with the following:


    java.net.InetAddress addr = java.net.InetAddress.getLocalHost(); server = new ServerSocket(200,0,addr);


    but the packet doesn't get through. any ideas?

  3. #3
    Join Date
    Nov 2003
    What are your output and forward default policy's, and do you have any rules in the nat or filter or mangle tables which could be interfering?

    Also try using a port > 1024, since iirc on unix/linux systems ports < 1024 require root priviledges to bind to, though if that were the problem I would expect that you would have had an exception thrown when you tried binding to it.

  4. #4
    Join Date
    Nov 2003

    default policies in forward and output are set to accept, with no other rules or chains called.

    I tried a higher port number (1050), but to no avail. It seems to be connnecting eventually, after 3 minutes or so. The socket looks as follows:

    server = ServerSocket[addr=localhost/, port=0, localport=1050]

    But I don't see why it should take so long.........?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.