TCP/IP ports necessary for CIFS/SMB operation

1,755

Solution 1

Ports 137-139 are for NetBios/Name resolution. Without it you will have to access machines by IP address opposed to NetBIOS name. Example \\192.168.1.100\share_name opposed to \\my_file_server\share_name

So port 445 is sufficient if you can work with IP addresses only.

Solution 2

This configuration worked for me: 137/UDP, 138/UDP, 139/TCP and 445/TCP. Source and additional information at: http://www.icir.org/gregor/tools/ms-smb-protocols.html.

So these are the iptables rules for my Samba server:

# The router doesn't need SMB access.
-A INPUT -s 192.168.1.1 -p udp --dport 137 -j REJECT
-A INPUT -s 192.168.1.1 -p udp --dport 138 -j REJECT
-A INPUT -s 192.168.1.1 -p tcp --dport 139 -j REJECT
-A INPUT -s 192.168.1.1 -p tcp --dport 445 -j REJECT

# Actual Samba ports
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 137 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 138 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 139 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 445 -j ACCEPT
Share:
1,755

Related videos on Youtube

Dora
Author by

Dora

Updated on September 18, 2022

Comments

  • Dora
    Dora almost 2 years

    I'm totally new to Tkinter, so apologies if I'm saying something really wrong. I am implementing game fifteen in Python, which I wanna make visual with Tkinter. See the following board of 2x2:

    4 3
    2 x

    If you prompt x to swop with 3, those labels should be updated.So far I initialised a canvas, and have two code snippets, one to set up the board:

    def visualize():
        for i,row in enumerate(board):
            for j,column in enumerate(row):
                L = Label(root,text='   %s   '%board[i][j],bg='pink')
                if board[i][j] == d*d:
                    L = tk.Label(root,text='        ')
    

    And for the move function:

    def move():
        tile = int(raw_input('Which tile would you like to move: '))
        global board, blankx, blanky
        for i in range(d):
            for j in range(d):
                if(board[i][j] == tile):
                    if(i - 1 == blanky or i + 1 == blanky or j - 1 == blankx or j + 1 == blankx):
                        board[i][j] = d * d
                        board[blanky][blankx] = tile
                        blanky = i
                        blankx = j
                        return True
        return False
    

    Any ideas on how to incorporate the labels into my canvas, and how to incorporate move as a valid event on the canvas? Thanks a lot

  • Jonathan
    Jonathan over 12 years
    At my site, NetBIOS names are always the same as DNS names. So if I refer to machines by hostname, will Windows be able find the machine through DNS without using NetBIOS?
  • Tim
    Tim over 12 years
    As long as you have functioning DNS available to the client it should suffice.
  • Dora
    Dora over 8 years
    Thanks a lot, this is really useful! I was wondering whether you know how I could put this into a ' while won() == False: ' so that the game only goes on until the game is solved? It's not working the way I'm trying with simple including this Tkinter snippet into the loop.
  • furas
    furas over 8 years
    mainloop() should be the only (endless) loop in Tkinter. I think you should't use while won() == False:. Better in move() use if won(): print("Hurray!")
  • furas
    furas over 8 years
    I modified code to add won() function and "Hurray" label. I use Frame to easily hide all buttons behind label. It still needs shuffle() function.
  • Dora
    Dora over 8 years
    Thanks a lot, saved me a lot of frustration. I did it with labels in the end, and now im trying to work on resetting the board. I thought shuffle() could be the same as init where I set the values for board[i][j]. But it seems like by clicking anywhere after winning, the board stays the same, however the values do go back to the initial board values. I thought after shuffling though the mainloop() will restart itself, and the board will again be set up according to the new (initial) board values. Any idea on where I'm wrong?
  • furas
    furas over 8 years
    if you have board with new values then you have to use it to change buttons text - buttons[y][x]['text'] = board[y][x]
  • furas
    furas over 8 years
    you can use tkinter.StringVar() in board to keep values and assign StringVar() to Button using textvariable= instead of text=. When you change value in StringVar in board it will change text on button.
  • furas
    furas over 8 years
    I made new version with StringVar - see new code in answer.
  • Dora
    Dora over 8 years
    Thanks for the updates! Okay, didn't work with merely updating the text label for me. I'm trying to initialize the board (that's given in yours). I want it to be according to the user's input as dimension. Not too familiar with stringvars, but I can't just append it to a list, it seems like. Can you help me with that please? Rest looks fine after the initialization
  • furas
    furas over 8 years
    you can use StringVar() as other objects. You assign it to variable some_stringvar_text = StringVar() or append to list some_list.append(StringVar()) or some_list.append(some_stringvar_text) . But you have to use get() and set() like print(some_stringvar_text.get()) and some_stringvar_text.set("Hello"). If you have problem then put code on pastebin.org or ideone.com and send link (like this pastebin.com/p2KAfsHH ).
  • Dora
    Dora over 8 years
    That might be a better idea:) Here it is: pastebin.com/MVXjk1fV Really appreciate your help! The messy part is the setup function. Now the board seems to be fine, but visually it doesn't show that on the window.
  • Dora
    Dora over 8 years
    Thanks for this, I changed a few details as it wasn't displaying, and it all works fine. Except one thing: in setup(): I say button.lower() to make it disappear once clicked, but button is a non-referenced variable. So I can't make it disappear after resetting the board. Making it global won't work either.. I just wonder why this is while button.lift() was fine in the play() method
  • furas
    furas over 8 years
    show code. In previous version there is no button variable but label and it is reference to Button. Maybe you get error message (in console) which could help.
  • Dora
    Dora over 8 years
    pastebin.com/B6Vq3w6R In setup() for bn.lower() I get: "global name 'bn' is not defined"
  • furas
    furas over 8 years
    now I see - setup() have to be after bn=Button() . Now you call setup() before you create bn` variablem. Remove first setup() - leave second setup() - you don't have to call it twice.
  • Dora
    Dora over 8 years
    Gooooot it!! There was an extra function call right before root = tk.Tk() ! Thank you :)
  • furas
    furas over 8 years
    code: pastebin.com/C303uP6U . You don't need buttons = [] any more. You can remove game_running = True before mainloop() because setup() sets game_running = True
  • Samuel Harmer
    Samuel Harmer almost 8 years
    @Hrqls In theory, yes, but AFAIK opening up your SMB to the whole world is a very bad idea.
  • DarkMoon
    DarkMoon over 7 years
    Given that the OP asked about Windows computers and their level of understanding of iptables is completely unknown, this would be better written out than as a completely different system's configuration file.
  • Gabor
    Gabor over 5 years
    In plain English, UDP 137 and 138, TCP 139 and 445
  • dess
    dess over 4 years
    @Styne666 , totally agree. Even more: opening anything, which does not have adequate security support, to the whole Internet is generally bad idea. I would recommend to use IPsec transport mode to protect it at least.
  • Feriman
    Feriman over 3 years
    If you are access to this remote machine with DDNS, allow only TCP 445 because it's enough. I tested it today and works well.